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 mapped through the given translation table. If there are more than one values to be translated, a dictionary is passed to maketrans function to create a translation table.
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 :
Input original array : ['Weeks' 'our' 'Weeks'] Output translated array: ['Geeks' 'for' 'Geeks']
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course