-1

I currently struggling with extracting certain columns and rows from a matrix stored as a numpy.ndarray.

I have a list in which I've appended these numpy.ndarrays.

This list is stored in a variable named data

print data[0].shape

outputs this

(400, 288)

Which I've according to the documentation have understood being the matrix has 400 rows, and 288 columns.

How do I extract all the 288 seperately?

Example:

>> import numpy as np
>> data = np.random.rand(3,3)
>> print data

[[ 0.97522481  0.57583658  0.68582806]
 [ 0.88509883  0.22261933  0.84307038]
 [ 0.59397925  0.51592125  0.54346909]]

How do I print the columns separately of this 3x3 matrix, first being

[0.97522481 , 0.88509883, 0.59397925 ]

without outputting the others?

3
  • A short example describing the desired behavior would be helpful Commented Nov 12, 2016 at 18:58
  • Depending on the use case, you might not need to separate out the columns as you can simply slice - docs.scipy.org/doc/numpy/reference/… Commented Nov 12, 2016 at 18:58
  • 1
    data[:,0] to look at the 1st column Commented Nov 12, 2016 at 21:23

1 Answer 1

0

Is it what you are looking for?

import numpy as np
arr = np.array([[1, 2], 
                [3, 4], 
                [5, 6]])
print(arr.shape)
# (3, 2)
print(list(data.T))
# [array([1, 3, 5]), array([2, 4, 6])]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.