English, asked by anushapanguluri98, 2 days ago

In [ ]: def q2 (A): III Input: A - MXN Numpy array Output: Returns an NumPy array that consists of every entry of A that has even row index and has an odd column index. Example: A = np.array([[ 1 2 3 4 5] [ 6 7 8 9 10) [11 12 13 14 15] [16 17 18 19 20] [21 22 23 24 25]]) Output = np.array([[ 2 4] [12 14] [22 24]]) I INI​

Answers

Answered by MitanshRao
0

Explanation:

Let's say you have this array, x:

>>> import numpy

>>> x = numpy.array([[ 1, 2, 3, 4, 5],

... [ 6, 7, 8, 9, 10],

... [11, 12, 13, 14, 15],

... [16, 17, 18, 19, 20]])

To get every other odd row, like you mentioned above:

>>> x[::2]

array([[ 1, 2, 3, 4, 5],

[11, 12, 13, 14, 15]])

To get every other even column, like you mentioned above:

>>> x[:, 1::2]

array([[ 2, 4],

[ 7, 9],

[12, 14],

[17, 19]])

Then, combining them together yields:

>>> x[::2, 1::2]

array([[ 2, 4],

[12, 14]])

Similar questions