Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

function
numpy
python
numpy.any()
communitycreator

What is the numpy.any() function in NumPy?

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The any() function in NumPy is used to check if all the elements of an array along a given axis evaluate to True.

Syntax

numpy.any(a, axis=None, out=None, keepdims=<no value>, *, where=<no value>)

Required parameter value

The any() function takes a mandatory parameter, a, which represents the input array or collection of objects that can be converted to an array.

Optional parameter values

The any() function takes the following optional parameter values:

  • axis: This represents the axis or axes along which a logical AND reduction operation is performed. The default value is (axis = None) and when negative, it counts from the last to the first axis.
  • out: This represents an alternate output array in which to place to the result. It must have the same shape as the expected output array.
  • keepdims: If this is set to True, axes which are reduced are left in the result as dimensions with size one.
  • where: This represents choice of elements to check for any True values.

Return value

The any() function returns a boolean value or array.

Example

import numpy as np

# creating an array
my_array = np.arange(6) + 1

# calling the any() function 
new_array = np.any(my_array)

# printing the array
print(new_array)
Implementing any() function in NumPy

Explanation

  • Line 1: We import the numpy module.
  • Line 4: We create an array variable my_array.
  • Line 7: We apply the any() function on the array my_array. The result is assigned to a new variable new_array.
  • Line 10: We print the variable new_array.

RELATED TAGS

function
numpy
python
numpy.any()
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring