【问题标题】:Multiplying each element from a list by a scalar将列表中的每个元素乘以标量
【发布时间】:2016-11-03 10:51:00
【问题描述】:

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

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: 列表赋值索引超出范围

【问题讨论】:

  • 错误是什么?而且,t 不是一个值!
  • @Aidin: IndexError: list assignment index out of range
  • 是的。 t 应该是一个变量(时间)。我仍然需要弄清楚如何正确准备我的数据,这是我第一次在 python 中做动画。
  • 我不是很了解python,但是你不需要像在循环中那样为每个t值做这个,而不是仅仅插入t吗?我的意思是,现在你有两个变量,xt
  • 您希望realResponse 成为矩阵吗?

标签: python list numpy


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2019-10-15
    • 1970-01-01
    • 2019-03-28
    • 2016-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 2020-08-14
    相关资源
    最近更新 更多