Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
numpy
communitycreator

What is the numpy.char.isnumeric() function in Python?

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 char.isnumeric() function in Python returns `true` if there are only numeric characters in the element of a given input array. Otherwise, it returns false.

Pictorial description

Illustration of how char.isnumeric() function works

Syntax

char.isnumeric(a)
The syntax for the char.isnumeric() function

Parameters

The char.isnumeric() function takes an array as a parameter.

Return value

The char.isnumeric() function returns an array of boolean values with the same shape as the input array, a.

Example

import numpy as np
# creating an input array
a = np.array(["Hi", "25", "3L", "6C", "2"])
# invoking the char.isnumeric() function
myarray = np.char.isnumeric(a)
# printing the input array
print(a)
# printing the output arrays
print(myarray)
Implementing the char.isnumeric() function

Explanation

  • Line 1: We import thenumpymodule.
  • Line 3: We create an input array a using the array() function of numpy.
  • Line 6: We invoke the char.isnumeric() function on the input array. The result is assigned to a variable, myarray.
  • Line 9: We print the input array, a.
  • Line 12: We print myarray.

RELATED TAGS

python
numpy
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