python-3.x - 如何将 Excel 工作表中的 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')
解决方案
推荐阅读
- javascript - 在客户端不使用 ActiveX 将文件从一个文件夹复制到另一个文件夹
- sql-server - 在 SQL Server 中连接两个表
- matlab - 线性规划在 Matlab 中使用 linprog 可行,使用 Gurobi 不可行
- python - 压缩完所有图片后结束循环
- angular6 - OpenIddict 令牌请求被拒绝,因为授权码或刷新令牌无效
- regex - Sed 到正则表达式列名
- python - 默认的 sklearn TfidfVectorizer 预处理器有什么作用?
- r - 更改 RGtk2 hbox 高度
- powershell - 具有初始容量的 Powershell 哈希表
- javascript - 对多于一列的数组进行字母数字排序