numpy.compress(condition, array, axis = None, out = None) : Return selected slices of an array along mentioned axis, that satisfies an axis.
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 elements axis : [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
Copy of array with elements of input_array, that satisfies condition and along given axis
Original array : [[0 1] [2 3] [4 5] [6 7] [8 9]] Sliced array : [[2 3]] Sliced array : [[2 3]]
This codes won’t run on online-ID. Please run them on your systems to explore the working.
This article is contributed by Mohit Gupta_OMG 😀. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Python | Index of Non-Zero elements in Python list
- Important differences between Python 2.x and Python 3.x with examples
- Python | Merge Python key values to list
- Reading Python File-Like Objects from C | Python
- Python | Convert list to Python array
- Python | Add Logging to a Python Script
- Python | Sort Python Dictionaries by Key or Value
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Add Logging to Python Libraries
- Python | Visualizing O(n) using Python
- bin() in Python
- Use of min() and max() in Python
- Python Set | pop()
- Any & All in Python