python - Multiple dtypes in a Numpy array -
i have following data set in numpy array:
array 1:
[[a, 1, 20] [a, 3, 40] [b, 1, 20] [b, 2, 40] [c, 5, 90]]
array 2:
[[a, 2] [a, 5]]
what i'm trying accomplish following: array2[0,0]=a
, , array2[0,1]=2
want interpolate first array find a,2,30
.
to i'm using np.where(array1==item)[0]
looks 'a'
, can't interpolate though because dtype
used import string, not int.
it's been while since i've used numpy if i'm in weeds please let me know.
i'm not entirely clear on you're trying do, sounds want specify aggregate dtype.
this explained in detail in dtype
docs.
for example, here's way specify each row has 1-character string , 64-bit native float (when don't care field names are):
dt = np.dtype('u1, f8')
there of course other ways write this; read full page details.
and, assuming you've read in loadtxt
, docs there have nice example of using such dtype. example:
>>> s2 = 'a 2\na 5\n' >>> i2 = io.stringio(s2) >>> a2 = np.loadtxt(i2, 'u1, i4') >>> a2 array([('a', 2), ('a', 5)], dtype=[('f0', '<u1'), ('f1', '<i4')])
Comments
Post a Comment