np.sin(myArray)的numpy Typerror

时间:2018-06-26 22:24:57

标签: python arrays numpy

不确定为什么print(np.sin(myArray))会引发错误,而 np.sin(np.array([1,2,3])))工作正常。这是我的代码:

import numpy as np
myArray = np.array(['1', '2', '3'])
print(myArray)                       # ['1' '2' '3']
print(np.sin(myArray))               # THIS LINE GIVES AN ERROR
print(np.sin(np.array([1, 2, 3])))   # [0.84147098 0.90929743 0.14112001]
print(np.sin([1, 2, 3]))             # [0.84147098 0.90929743 0.14112001]

2 个答案:

答案 0 :(得分:1)

myArray = np.array(['1','2','3'])需要更改为myArray = np.array([1、2、3])

答案 1 :(得分:-1)

当您使用数字类型数组时,您正在字符串数组上调用np.sin