![]() |
VOOZH | about |
The numpy.char.swapcase() function is used to convert uppercase characters to lowercase and lowercase characters to uppercase in each string element of a NumPy array. It works element-wise and returns a new array with the modified strings.
For Example: This example demonstrates how np.char.swapcase() swaps the case of each character in a single string array.
['hELLO wORLD']
numpy.char.swapcase(arr)
Example 1: In this example, we apply swapcase() on a string array containing alphanumeric values.
Array: ['P4Q R' '4q Rp' 'Q Rp4' 'rp4q'] Result: ['p4q r' '4Q rP' 'q rP4' 'RP4Q']
Example 2: In this example, we use swapcase() on an array of words.
Array: ['Geeks' 'For' 'Geeks'] Result: ['gEEKS' 'fOR' 'gEEKS']
Example 3: Here, swapcase() is applied to sentences with mixed cases.
Array: ['NumPy Is Powerful' 'PYTHON is Fun'] Result: ['nUMpY iS pOWERFUL' 'python IS fUN']