You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
import random
import numpy as np
def random_points ( ) :
x = [ ]
y = [ ]
for i in range ( 20 ) :
x_ = random . uniform ( 0 , 1000 ) # 生成随机浮点数
y_ = random . uniform ( 0 , 1000 ) # 生成随机浮点数
x . append ( x_ ) # 加入列表
y . append ( y_ )
x = np . array ( x ) # 列表转数组
y = np . array ( y )
arr = np . array ( list ( zip ( x , y ) ) ) # 将两个一维数组拼接成二维数组
return arr
# if __name__ == '__main__':
# arr = random_points()
# print(arr)
def compute_curveData ( num , step , coefficient ) : # coefficient代表二次函数系数, 数组形式
def quadratic_function ( x ) : # 构造二次函数y = a * X^2 + b * X + C
return coefficient [ 0 ] * x * * 2 + coefficient [ 1 ] * x + coefficient [ 2 ]
x_values = np . arange ( 0 , num , step )
y_values = quadratic_function ( x_values ) # 调用quadratic_function(x)函数得到y值
curve_data = np . column_stack ( ( x_values , y_values ) ) # 将两个一维数组堆叠成二维数组,形成(x,y)的形式
return curve_data
if __name__ == ' __main__ ' :
coefficient = [ 1 , 2 , 3 ]
ans = compute_curveData ( 1000 , 250 , coefficient )
print ( ans )