numpy - Python .npy file: how to multiply or divide the data? -


i have data file in .npy format. simplicity, let's take following case

data={} data["a"]=[1.,2.,3.,4.,5.] data["b"]=[10,20,30,40,50] a=data["a"] b=data["b"] c1=a*b c2=a/b c3=np.sqrt(a/b) 

this gives following error

typeerror: can't multiply sequence non-int of type 'list' typeerror: unsupported operand type(s) /: 'list' , 'list' 

how above operations these type of arrays? thank you

as says, a , b lists. think trying operations on list items have iterate through each item. can list comprehension this:

c1 = [x*y x,y in zip(a,b)] c2 = [x/y x,y in zip(a,b)] 

and etc


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -