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
Post a Comment