Python - 一个标量的多个列表

Python - multiple list by a scalar

参考这个问题link In Python how will you multiply individual elements of a list with a floating point or integer number?

我用import numpy as np;然后将一个列表与一个浮动数字相乘,并将更新后的值存储在同一个列表中。但是,新值就像 [[array([ 10.])] .....

现在我想删除数组并使用具有整数值的列表。

您想将 np.array() 变回列表吗?

import numpy as np
P=2.45
S=[22, 33, 45.6, 21.6, 51.8]
SP = P*np.array(S)
SP_LIST =list(SP)

作为post你link还包含:

[x * P for x in S]

returns直接上榜