hh=[[82.5], [168.5]]
N=1./5
ll=N*hh
What I'm doing wrong? I received error :
"can't multiply sequence by non-int of type 'float'"
I try to add float(), but this is not solve my problem;
I need to multiply each element in array... thanks to all
hh=[[82.5], [168.5]]
N=zip(*hh)
ll = [[x*N for x in y] for y in hh]
???
When you multiply a sequence by X
in Python, it doesn't multiply each member of the sequence - what it does is to repeat the sequence X
times. That's why X has to be an integer (it can't be a float).
What you want to do is to use a list comprehension:
hh = [[82.5], [168.5]]
N = 1.0 / 5
ll = [[x*N for x in y] for y in hh]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With