我有一个numpy数组,想将它乘以一个标量,但一直出现错误提示:
TypeError: unsupported operand type(s) for *: 'numpy.ndarray' and 'int'
我的代码是:
Flux140 = ['0.958900', 'null', '0.534400']
n = Flux140*3
Flux140[Flux140 == 'null'] = '-1'
Flux140 = Flux140.astype(float)
'null'
更改为其他内容,您可以首先进行更改:Flux140[Flux140 == -1] = np.nan
tripled = Flux140 * 3
Flux140
看起来更像是一个字符串列表而不是 numpy 数组。元素是字符串,为了符合 Python 语法,它们之间缺少逗号。 - user2304916*
就会成为列表重复符号。这看起来像是一个 NumPy 对象数组的打印表示形式。 - user2357112