简体   繁体   English

我该如何解决:TypeError:/:'tuple'和'float'不支持的操作数类型?

[英]How can I fix this: TypeError: unsupported operand type(s) for /: 'tuple' and 'float'?

I am trying to use the row values to get the C_vel values. 我正在尝试使用行值来获取C_vel值。

The code: 编码:

wb = op.load_workbook('Canopy\Scripts\De Velliers.xlsx')
ws = wb ['Sheet1']                         
for row in ws.rows:
    for cell in row:
        print(cell.value)
        print "----------"
        C_vel = ws.rows / (A_c * rho)
        print "C_vel: ", C_vel

The error message: 错误信息:

TypeError                      
Traceback (most recent call last)
C:\Users\Fraixxer Fraiz\Canopy\scripts\franis 1.py in <module>()
     26         print(cell.value)
     27         print "----------"
---> 28         C_vel = ws.rows / (A_c * rho)
     29         print "C_vel: ", C_vel
     30 

TypeError: unsupported operand type(s) for /: 'tuple' and 'float' 

You can not do mathematical operations on tuples. 您不能对元组进行数学运算。 Using numpy you could convert the tuple to an array first. 使用numpy,您可以先将元组转换为数组。 Mathematical operations can be performed on numpy arrays. 可以对numpy数组执行数学运算。

    import numpy as np
    wb = op. load _ workbook ('Canopy\Scripts\De Velliers.xlsx')
    ws = wb ['Sheet1']                            
    for row in ws . rows:
        for cell in row:
            print(cell. value)
            print "----------"
            C_vel = np.array(ws. rows)/ (A_c * rho)
            print "C_vel:",C_vel

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:+的不支持的操作数类型:&#39;float&#39;和&#39;tuple&#39; - TypeError: unsupported operand type(s) for +: 'float' and 'tuple' 如何解决 TypeError: 不支持的操作数类型 +: &#39;float&#39; 和 &#39;tuple&#39; - How to solve TypeError: unsupported operand type(s) for +: 'float' and 'tuple' 如何修复 Python TypeError:不支持的操作数类型“int”和“tuple” - How to fix Python TypeError: unsupported operand type(s) 'int' and 'tuple' 如何修复错误 - TypeError:不支持的操作数类型 - :&#39;tuple&#39;和&#39;int&#39; - How to fix error - TypeError: unsupported operand type(s) for -: 'tuple' and 'int' 如何修复“TypeError:*:'NoneType'和'float'不支持的操作数类型”? - How to fix “TypeError: unsupported operand type(s) for *: 'NoneType' and 'float'”? 如何修复TypeError:函数中*:&#39;instance&#39;和&#39;float&#39;不受支持的操作数类型 - How to fix TypeError: unsupported operand type(s) for *: 'instance' and 'float' in a function 如何修复错误? TypeError: 不支持的操作数类型 -: 'tuple' 和 'int' - How do I fix the error? TypeError: unsupported operand type(s) for -: 'tuple' and 'int' 如何修复此错误:TypeError: unsupported operand type(s) for *: 'float' and 'function' in python - How do I fix this error: TypeError: unsupported operand type(s) for *: 'float' and 'function' in python TypeError:不支持的操作数类型/:'float'和'list':如何用float拆分lista? - TypeError: unsupported operand type(s) for /: 'float' and 'list': how can i split a lista with a float? 如何修复TypeError:不支持的操作数类型? - How to fix TypeError: unsupported operand type(s)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM