Home > database >  How to get desired output from 5 x 5 matrix | Numpy |
How to get desired output from 5 x 5 matrix | Numpy |

Time:11-14

I am solving a below question where i want to print the expected output from 5 x 5 matrix

5 x 5 matrix

0,  1,  3,   3,  4 
11,  6, 54,  8,  9 
12, 11, 10, 18,  4 
17, 16, 19, 10,  1 
21, 21, 52, 33, 22 

Expected output :

12 10
21 52

I tried this not able to apply logic

arr[2:,:3:2]

CodePudding user response:

Seems like you got some assignment work

Below code might work for you just try it

import numpy as np

arr=np.array([
[0,  1,  3,   3,  4 ],
[11,  6, 54,  8,  9 ],
[12, 11, 10, 18,  4 ],
[17, 16, 19, 10,  1 ],
[21, 21, 52, 33, 22 ] ] )

arr[2:,:3:2][::2]

Expected output :

array([[12, 10],
       [21, 52]])

Note : The code is tested on Google Collab

Incase found any issue feel free to edit it

  • Related