-1
$\begingroup$

I have few difficulties in picking values from an array. Here is a simplified version of the concerned part of the code. (If you would like to put the whole code please mention it)

n=2
m=8
test= test[:,-n*m:] 
test=test.reshape(test.shape[0],n,m)

So, I end up with :

test.shape= (350, 2, 8)

when I run the code I've got this:

array([[[0.01911469, 0.32352942, 0.18032786, ..., 0.006101  ,
         0.        , 0.        ],
        [0.01810865, 0.32352942, 0.18032786, ..., 0.006101  ,
         0.        , 0.        ]],

       [[0.01810865, 0.32352942, 0.18032786, ..., 0.006101  ,
         0.        , 0.        ],
        [0.01710262, 0.32352942, 0.1967213 , ..., 0.01297103,
         0.        , 0.        ]],

       [[0.01710262, 0.32352942, 0.1967213 , ..., 0.01297103,
         0.        , 0.        ],
        [0.01408451, 0.32352942, 0.18032786, ..., 0.00763907,
         0.        , 0.        ]],

       ...,

       [[0.01006036, 0.2647059 , 0.26229507, ..., 0.40558836,
         0.        , 0.        ],
        [0.01006036, 0.2647059 , 0.26229507, ..., 0.41399646,
         0.        , 0.        ]],

       [[0.01006036, 0.2647059 , 0.26229507, ..., 0.41399646,
         0.        , 0.        ],
        [0.00804829, 0.2647059 , 0.24590163, ..., 0.4208665 ,
         0.        , 0.        ]],

       [[0.00804829, 0.2647059 , 0.24590163, ..., 0.4208665 ,
         0.        , 0.        ],
        [0.01207243, 0.2794118 , 0.26229507, ..., 0.42621556,
         0.        , 0.        ]]], dtype=float32)

My question is how can I get only the values of the first columns like this:

array([[0.01911469],
       [0.01810865],
       [0.01810865],
       [0.01710262],
       [0.01710262],
       [0.01408451],
        ...,
       [0.01006036],
       [0.01006036], 
       [0.01006036],
       [0.00804829],
       [0.00804829],
       [0.01207243]], dtype=float32)

I have tried this:

test=test[:,:,:1]

but I've got this instead of what I'm looking for:

array([[[0.01911469],
        [0.01810865]],

       [[0.01810865],
        [0.01710262]],

       [[0.01710262],
        [0.01408451]],

       ...,

       [[0.01006036],
        [0.01006036]],

       [[0.01006036],
        [0.00804829]],

       [[0.00804829],
        [0.01207243]]], dtype=float32)
$\endgroup$

1 Answer 1

1
$\begingroup$

Try the following code. As you want all first value of zeroth dimension.

test=test[:,0,0]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.