numpy string operations | swapcase() function (original) (raw)
Last Updated : 28 Nov, 2022
numpy.core.defchararray.swapcase(arr) function return element-wise a copy of the string with uppercase characters converted to lowercase and lowercase characters converted to uppercase.
Syntax: numpy.char.swapcase(arr) Parameters: arr : [ array_like ] Input array which may be str or unicode. Returns : [ndarray] Output lowercased array of str or unicode, depending on input type.
Code #1:
Python3
import
numpy as geek
in_arr
=
geek.array([
'P4Q R'
,
'4q Rp'
,
'Q Rp4'
,
'rp4q'
])
print
("
input
array : ", in_arr)
out_arr
=
geek.char.swapcase(in_arr)
print
("output swapcased array :", out_arr)
Output:
input array : ['P4Q R' '4q Rp' 'Q Rp4' 'rp4q'] output swapcasecased array : ['p4q r' '4Q rP' 'q rP4' 'RP4Q']
Code #2:
Python3
import
numpy as geek
in_arr
=
geek.array([
'Geeks'
,
'For'
,
'Geeks'
])
print
("
input
array : ", in_arr)
out_arr
=
geek.char.swapcase(in_arr)
print
("output swapcasecased array :", out_arr )
Output:
input array : ['Geeks' 'For' 'Geeks'] output swapcasecased array : ['gEEKS' 'fOR' 'gEEKS']
Similar Reads
- numpy string operations | upper() function numpy.core.defchararray.upper(arr): function is used to return an array with the elements converted to uppercase. Parameters: arr : [ array_like ] Input array which may be str or unicode. Returns : [ndarray] Output uppercased array of str or unicode, depending on input type. Code #1: # Python Progra 1 min read
- numpy string operations | translate() function numpy.core.defchararray.translate(arr, table, deletechars=None) is another function for doing string operations in numpy. For each element in arr, it returns a copy of the string where all characters occurring in the optional argument deletechars are removed, and the remaining characters have been m 1 min read
- numpy string operations | title() function numpy.core.defchararray.title(arr): function is used to Return element-wise title cased version of string or unicode.Title case words start with uppercase characters, all remaining cased characters are lowercase. Parameters: arr : [ array_like ] Input array which may be str or unicode. Returns : [nd 1 min read
- Numpy - String Functions & Operations NumPy String functions belong to the numpy.char module and are designed to perform element-wise operations on arrays. These functions can help to handle and manipulate string data efficiently. Table of Content String OperationsString Information String Comparison In this article, we’ll explore the v 5 min read
- numpy string operations | lower() function numpy.core.defchararray.lower(arr) function is used to return an array with the elements converted to lowercase. Parameters: arr : [ array_like ] Input array which may be str or unicode. Returns : [ndarray] Output lowercased array of str or unicode, depending on input type. Code #1: # Python Program 1 min read
- numpy string operations | rstrip() function numpy.core.defchararray.rstrip(arr, chars=None) is another function for doing string operations in numpy. It returns a copy with the trailing characters removed for each element in arr. Parameters: arr : array_like of str or unicode. char : [str or unicode, optional] the set of characters to be remo 2 min read
- numpy string operations | lstrip() function numpy.core.defchararray.lstrip(arr, chars=None) is another function for doing string operations in numpy. It returns a copy with the leading characters removed for each element in arr. Parameters: arr : array_like of str or unicode. char : [str or unicode, optional] the set of characters to be remov 2 min read
- numpy string operations | isupper() function numpy.core.defchararray.isupper(arr) function returns True for each element if all cased characters in the string are uppercase and there is at least one character, it returns false otherwise. Parameters: arr : array_like of str or unicode Returns : [ndarray] Output array of bools. Code #1: # Python 1 min read
- numpy string operations | islower() function numpy.core.defchararray.islower(arr) function returns True for each element if all cased characters in the string are lowercase and there is at least one cased character, It returns false otherwise. Parameters: arr : array_like of str or unicode Returns : [ndarray] Output array of bools. Code #1: # 1 min read
- Numpy string operations | replace() function In the numpy.core.defchararray.replace() function, each element in arr, return a copy of the string with all occurrences of substring old replaced by new. Syntax : numpy.core.defchararray.replace(arr, old, new, count = None) Parameters : arr : [array-like of str] Given array-like of string. old : [s 1 min read