使用math.sin时报错only size-1 arrays can be converted to Python scalar

代码:

import numpy as np
x = np.linspace(0,1,6)
def f(x):
	return math.sin(x)
y = f(x)

报错: only size-1 arrays can be converted to Python scalars

解决方案:用numpy里的sin代替math库里的sin

import numpy as np
x = np.linspace(0,1,6)
def f(x):
	return np.sin(x)
y=f(x)
	

你可能感兴趣的:(问题记录)