The isupper() function of numpy.strings module

The isupper() function of numpy.strings module checks the whether a numpy Array has its string elements all made-up of uppercase letters.

String Operations Updated 30 Nov 2024 1 min read

Overview

  • The isupper() function of numpy.strings module checks whether all the strings elements of a NumPy array is made of all uppercase letters.

Example

python
# Example Python program that finds whether

            # the string elements of an ndarray consists of

            # all uppercase elements using the function

            # numpy.strings.isupper()

            import numpy

# Create a NumPy array of ASCII strings

            asciiStrings = numpy.ndarray(shape = (2, 2),

                                     dtype = numpy.dtype('S10'))

            asciiStrings[0][0] = "abCD"

            asciiStrings[0][1] = "xYz"

            asciiStrings[1][0] = "ALL"

            asciiStrings[1][1] = "none"

# Find whether the strings contain all uppercase letters

            res = numpy.strings.isupper(asciiStrings)

            print("ASCII strings:")

            print(asciiStrings)

            print("Are they comprised of all uppercase letters:")

            print(res)

Output

Output
ASCII strings:

[[b'abCD' b'xYz']

 [b'ALL' b'none']]

Are they comprised of all uppercase letters:

[[False False]

 [ True False]]