How to slice an array using python numpy Is there any numpy tutorial which has covered all its operations

0 votes
Unable to slice a numpy array.
Apr 24, 2018 in Python by anto.trigg4
• 3,440 points
970 views

1 answer to this question.

0 votes

Slicing is basically extracting particular set of elements from an array. It is pretty much similar to the one which is there in the list as well. For example: We have an array and we need a particular element (say 3) out of a given array.

import numpy as np
a=np.array([(1,2,3,4),(3,4,5,6)])
print(a[0,2])

Output – 3

Here, the array(1,2,3,4) is your index 0 and (3,4,5,6) is index 1 of the python numpy array. Therefore, we have printed the second element from the zeroth index. 
Taking one step forward, let’s say you need the 2nd element from the zeroth and first index of the array.

import numpy as np
a=np.array([(1,2,3,4),(3,4,5,6)])
print(a[0:,2])

Output –[3 5]

answered Apr 24, 2018 by Christine
• 15,790 points

Related Questions In Python

+4 votes
7 answers
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Is it possible to create an array with all values as zero in python?

You can use  np.zeros(4,3) This will create a 4 ...READ MORE

answered May 24, 2019 in Python by Anjali
855 views
+1 vote
2 answers

View onto a numpy array?

 just index it as you normally would. ...READ MORE

answered Oct 18, 2018 in Python by roberto
670 views
0 votes
1 answer

Printing a large numpy array

numpy.set_printoptions(threshold='nan') READ MORE

answered Jul 20, 2018 in Python by Nietzsche's daemon
• 4,260 points
1,515 views
+1 vote
3 answers

What are the ways of detecting outliners in Python

code from http://eurekastatistics.com/using-the-median-absolute-deviation-to-find-outliers  This uses the L1 distance ...READ MORE

answered Aug 24, 2018 in Python by eatcodesleeprepeat
• 4,710 points

reshown Aug 24, 2018 by Priyaj 957 views
0 votes
1 answer

how to download and install Django rest framework?

To install Django, you can simply open ...READ MORE

answered Apr 24, 2018 in Python by Christine
• 15,790 points
1,558 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP