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

Overview

The char.isalpha() function in NumPy is used to check if all characters of an element string are alphabetic or not. It returns True if it does contain all alphabets character(s), and False if otherwise.

Syntax

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

Parameter value

The char.isalpha() function takes a single parameter a which is the array of strings.

Return value

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

Example

import numpy as np
# creating an input array
a = np.array(['The', "342", "Hello", "A", "100"])
# implementing the char.isalpha() function
myarray = np.char.isalpha(a)
# printing the input array
print(a)
# printing the output arrays
print(myarray)

Explanation

Here is a line-by-line explanation of the code above:

  • Line 1: We import the numpy module.
  • Line 3: We create an input array a using the array() function.
  • Line 6: We implement the char.isupper() 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 the output array myarray.

Free Resources