numpy.core.defchararray.translate (arr, table, deletechars = None)
— another function to do string operations in numpy. For each item in arr, it returns a copy of the string in which all characters occurring in the optional deletechars argument are removed and the rest of the characters are displayed in this translation table. If more than one value needs to be translated, a dictionary is passed to the maketrans function to create the translation table.
Parameters:
arr: array_like of str or unicode.Input array.
table: Translate mapping specified to perform translations.
deletechars: String type, characters to be deleted.Returns: [ndarray] Output array of str or unicode with translated values.
Code # 1:
|
Output:
Input original array: [’Weeks’’ our’ ’Weeks’] Output translated arra y: [’Geeks’’ for’ ’Geeks’]