简体   繁体   中英

Multiplying each element from a list by a scalar

I have to prepare my data for animation and I ran across a problem

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)

Now this realResponse list turns out to be... well.. nothing

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

I don't know what seems to be the problem. I carefully followed this topic.

Anyway I also tried

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

and turns out to be an error:

IndexError: list assignment index out of range

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

returns an empty array. If you want an array between 1/10 with points every 1/10000 try:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM