Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
172 views
Welcome To Ask or Share your Answers For Others

1 Answer

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])]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...