如何将Excel工作表中的numpy浮点数组乘以常量?

时间:2019-07-28 16:22:41

标签: python-3.x numpy

我正在使用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')

0 个答案:

没有答案