Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to print even index values of any array | NumPy |

I am a learner , bit stuck not getting how do i print the even indexed value of an array

My code :

import numpy as np
arr_1 = np.array([2,4,6,11])
arr_1 [ (arr_1[ i for i in range(arr_1.size) ] ) % 2 == 0  ]

Expected Output :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

2,6

2 -> comes under index 0

6 -> comes under index 2

Both are even index

>Solution :

May be this could work for you

Code :

import numpy as np
arr_1 = np.array([2,4,6,11])
a =  [ arr_1[i] for i in range(arr_1.size) if ((i % 2) == 0)  ]
print(a)

Code is run in google Colab

Output

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading