python - Accessing a column of a NumPy array of structured arrays -
i've been given multidimensional numpy array, x
looks this:
array([ array([ 398.24475098, -196.1497345 , -110.79341125, ..., -1937.22399902, -6158.89355469, 1742.84399414], dtype=float32), array([ 32.27750397, -171.73371887, -342.6328125 , ..., -4727.4296875 , -4727.4296875 , -2545.10375977], dtype=float32), array([ 785.83660889, -234.88890076, 140.49914551, ..., -7982.19482422, -2127.640625 , -1434.77160645], dtype=float32), ..., array([ 181.93313599, -146.41413879, -416.02978516, ..., -4517.796875 , 10491.84570312, -6604.39550781], dtype=float32), array([ -1.37602341e+02, 1.71733719e+02, 7.13068867e+00, ..., 8.60104688e+03, 1.39115127e+04, 3.31622314e+03], dtype=float32), array([ 453.17272949, 152.49285889, 260.41452026, ..., 19061.60742188, 11232.8046875 , 7312.13964844], dtype=float32)], dtype=object)
i'm trying access each column (specifically i'm trying take standard deviation of each column). found this answer, , tried,
>>> x[:,0]
but returned error:
traceback (most recent call last): file "<stdin>", line 1, in <module> indexerror: many indices array
is possible convert structured array simple 2d numpy array access columns? or there way access these columns directly?
thanks!
edit
some more information on array:
>>> x.shape (8685,) >>> x[0].shape # same x[1], x[2], ... (3524,)
if it's help, used tree2array
function in root_numpy package produce array.
not sure how doing it,but seems work me straight prompt
a=np.zeros((2,6),dtype=np.float32) >>> array([[ 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0.]], dtype=float32) >>> a[:,2]=1 >>> array([[ 0., 0., 1., 0., 0., 0.], [ 0., 0., 1., 0., 0., 0.]], dtype=float32)
Comments
Post a Comment