Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Accessing Data Along Multiple Dimensions Arrays in Python Numpy
Next article icon
The numpy.compress() function returns selected slices of an array along mentioned axis, that satisfies an axis.
Syntax: numpy.compress(condition, array, axis = None, out = None)
Parameters :
condition :[array_like]Condition on the basis of which user extract elements.       Applying condition on input_array, if we print condition, it will return an arra      filled with either True or False. Array elements are extracted from the Indices having       True value.array     :Input array. User apply conditions on input_array elementsaxis      :[optional, int]Indicating which slice to select.          By Default, work on flattened array[1-D]out       :[optional, ndarray]Output_array with elements of input_array,                that satisfies condition
Return :
Copy of array with elements of input_array,that satisfies condition and along given axis
Python
# Python Program illustrating# numpy.compress methodimportnumpyasgeekarray=geek.arange(10).reshape(5,2)print("Original array :\n",array)a=geek.compress([0,1],array,axis=0)print("\nSliced array :\n",a)a=geek.compress([False,True],array,axis=0)print("\nSliced array :\n",a)
Output :
Original array :  [[0 1] [2 3] [4 5] [6 7] [8 9]]Sliced array :  [[2 3]]Sliced array :  [[2 3]]
Note : This codes won’t run on online-ID. Please run them on your systems to explore the working..

M

Mohit Gupta
Improve

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp