NumPy isnumeric() function

The isnumeric() function of the NumPy library returns True if there are only numeric characters in the string, otherwise, this function will return False.

Loaded: 1.70%Fullscreen

  • This function calls unicode.isnumeric in an element-wise manner.
  • It is important to note that Numeric characters generally include digit characters and all characters that have the Unicode numeric value property(means characters have a numeric value that can be either decimal, including zero and negatives, or a vulgar fraction)

Syntax for isnumeric():

The syntax required to use this function is as follows:


The above syntax indicates that isnumeric() function takes a single parameter.

In the above syntax, the argument arr is mainly used to indicate the input array of the strings or a single string, on which this function will be applied.

Returned Values:

This function will return an output array of boolean values, with True and False values corresponding to every string element, based on whether the string is numeric or not.

Example 1: With a string

In the below example, we will use the isnumeric() function with a simple string:

import numpy as np

string1 = "12Apple90"
print("The Input string is:")

x = np.char.isnumeric(string1)
print("The Output is:")


The Input string is:
The Output is:

Example 2: With an array

The code snippet is as follows where we will use isnumeric() function:

import numpy as np

inp_ar = np.array([ '1', '2000','90','3.5','0'] ) 
print ("The Input array : ")

outp_arr = np.char.isnumeric(inp_ar) 
print ("The Output array: ")


The Input array :
['1' '2000' '90' '3.5' '0']
The Output array:
[ True True True False True]

As you can see in the output for the code example above, the isnumeric() function returns False for a string with a numeric value with a decimal.

Follow Us On