w3resource

NumPy String: numpy.char.isdecimal() function

numpy.char.isdecimal() function

The numpy.char.isdecimal() function is used to check if all characters in a string are decimal characters. Returns True if there are only decimal characters in the element otherwise false.

This function is useful to validate whether a given string contains only decimal characters or not.

Syntax:

numpy.char.isdecimal(a)

Parameter:

Name Description Required /
Optional
a: array_like, unicode Input array. Required

Return value:

out : ndarray, bool - Array of booleans identical in shape to a.

Example: Checking if string contains only decimals using numpy.char.isdecimal()

>>> import numpy as np
>>> x = np.char.isdecimal('123')
>>> x
array(True)

In the above example, the string '123' is passed as an argument to the isdecimal() method which returns a boolean value True since it contains only decimal characters. The result is stored in a numpy array named x.

Example: Checking if a string contains only decimal characters using numpy.char.isdecimal()

>>> import numpy as np
>>> y = np.char.isdecimal('1.123')
>>> y
array(False)

In the above example the input string '1.123' contains a non-decimal character '.', so np.char.isdecimal() returns a boolean value of False when applied to this string.

Python - NumPy Code Editor:

Previous: isalpha()
Next: isdigit()



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/numpy/string-operations/isdecimal.php