将列表中的每个元素乘以

2024-09-30 00:31:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我必须为动画准备数据,我遇到了一个问题

t = numpy.linspace(0, 1/10, 1/10000)
x = [1, 3, 5, 7, 9]
S = [ 0.09642699 -1.75110819 -0.00915477 -0.42833324 -0.01772692 -0.00885592
 -0.01136874  0.4106214   0.09199903  1.73339635]
realResponse = [x * numpy.cos(311.64*t) for x in numpy.dot(eigenvector, modalconstant)]
#realResponse = numpy.delete(realResponse, my_list, axis=0)

现在这个realResponse列表变成了。。。好。。什么都没有

    print(realResponse)# prints: [array([], dtype=float64), 
                                  array([], dtype=float64), array([], dtype=float64),....

我不知道是什么问题。我仔细地跟着this topic.

反正我也试过了

realResponse = list()
for i in range(0, 10):
    realResponse[i] = S[i] * numpy.cos(eigenvalue[311.64*t)

结果是一个错误:

IndexError: list assignment index out of range


Tags: 数据innumpyforrange动画cosarray
1条回答
网友
1楼 · 发布于 2024-09-30 00:31:10

numpy.linspace(0, 1/10., 1/10000.)

返回空数组。如果您想要一个1/10之间的数组,每1/10000个点一个,请尝试:

numpy.arange(0, 1/10., 1/10000.)

相关问题 更多 >

    热门问题