我正在使用xlrd
包从Excel文件中读取值,并将它们存储到数组中。我打印了数组,并从Excel获取了值。现在,我想用一个常数乘以数组:
def getExcel():
book = xlrd.open_workbook(filedialog.askopenfilename())
sheet = book.sheet_by_index(5)
sheet.cell_value(0, 0)
y = []
ydata = np.array(y, dtype = np.float32)
x = []
angle = np.array(x, dtype = np.float32)
i=0
while (i<sheet.nrows):
if (i%2)>0:
angle = np.append(angle, sheet.cell_value(i, 0))
else:
ydata = np.append(ydata, sheet.cell_value(i, 0))
i+=1
constant = sheet.cell_value(1, 4)
rad = np.multiply(angle, 0.0174)
print(rad)
我希望angle
数组的所有元素都乘以0.0174
,但出现如下错误:
line 27, in getExcel rad = np.multiply(angle, 0.0174)
numpy.core._exceptions.UFuncTypeError: ufunc 'multiply' did not contain a
loop with signature matching types (dtype('<U32'), dtype('<U32')) ->
dtype('<U32')