Computer Science, asked by shonali327, 11 months ago

Which of the following would extract all the rows of the first 3 columns in a given numpy 2D array ‘a’?


a[ : , :2]


a[( : , :2)]


a[ : , :3]


a[( : , :3)]


Answers

Answered by RohanBorgohain18
5

Answer: a[: , : 3]

Explanation: a[ : , :3] extracts all the rows of the first 3 columns. Note that even though the first 3 columns have the indices 0, 1, and 2 respectively, we need to mention a[ : , :3] instead of a[ : , :2] since the last column index mentioned is not included, i.e. a[ : , :2] will give you just the first two columns, i.e. 0 and 1.

Similar questions