NumPy | Python Methods and Functions

** **

** numpy.compress (condition, array, axis = none, out = none): ** returns selected slices of the array along the specified axis that satisfy the axis.

** 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 program illustrating `

` # numpy.compress method `

` import `

` numpy as geek `

` array `

` = `

` geek.arange (`

` 10 `

`). reshape (`

` 5 `

`, `

` 2 `

`) `

< code class = "functions"> print ` (`

` "Original array:" `

` , array) `

` a `

` = `

` geek.compress ([`

` 0 `

`, `

` 1 `

`], array, axis `

` = `

` 0 `

`) `

` print `

` (`

` "Sliced array:" `

`, a) `

` a `

` = `

` geek. compress ([`

` False `

`, `

` True `

`], array, axis `

` = `

` 0 `

`) `

` print `

` ( `

` "Sliced array:" `

`, a) `

` `

** Output: **

Original array: [[0 1] [2 3] [4 5] [6 7] [8 9]] Sliced array: [[2 3]] Sliced array: [[2 3]]

** Links: **

https://docs.scipy.org/doc/numpy-dev/reference/generated/numpy .compress.html

** Notes: **

These codes will not work for online IDs. Please run them on your systems to see how they work.

,

This article is provided by ** Mohit Gupta_OMG
**

Cloud computing provides the capability to use computing and storage resources on a metered basis and reduce the investments in an organization’s computing infrastructure. The spawning and deletion ...

10/07/2020

Efficiently perform data collection, wrangling, analysis, and visualization using Python. Recent advancements in computing and artificial intelligence have completely changed the way we understand ...

23/09/2020

Python Workout isn’t designed to teach you Python, although I hope and expect that you’ll learn quite a bit along the way. It is meant to help you improve your understand- ing of Python and how to...

23/09/2020

This first edition of Strategic Engineering for Cloud Computing and Big Data Analytics focuses on addressing numerous and complex, inter-related issues which are inherently linked to systems engineeri...

10/07/2020

X
# Submit new EBook