0 votes
1 view
in Python by (47.8k points)

Suppose I have:

test = numpy.array([[1, 2], [3, 4], [5, 6]])

test[i] gets me ith line of the array (eg [1, 2]). How can I access the ith column? (eg [1, 3, 5]). Also, would this be an expensive operation?

1 Answer

0 votes
by (107k points)

Python has a wonderful method that is called as slicing this can be used to access the ith column of a NumPy multidimensional array we will use this as follows:-

import numpy as np

test = np.array([[1, 2], [3, 4], [5, 6]])

print(test[:,0])

image

Related questions

0 votes
2 answers
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 17, 2019 in Python by Sammy (47.8k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...