What is the numpy.char.isnumeric() function in Python?
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
Syntax
char.isnumeric(a)
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 arraya = np.array(["Hi", "25", "3L", "6C", "2"])# invoking the char.isnumeric() functionmyarray = np.char.isnumeric(a)# printing the input arrayprint(a)# printing the output arraysprint(myarray)
Explanation
- Line 1: We import the
numpymodule.
- Line 3: We create an input array
ausing thearray()function ofnumpy.
- 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.