How to split the element of a given NumPy array with spaces?
To split the elements of a given array with spaces we will use numpy.char.split(). It is a function for doing string operations in NumPy. It returns a list of the words in the string, using sep as the delimiter string for each element in arr.
arr : array_like of str or unicode.Input array.
sep : [ str or unicode, optional] specifies the separator to use when splitting the string.
maxsplit : how many maximum splits to do.
Returns : [ndarray] Output Array containing of list objects.
['PHP C# Python C Java C++'] [list(['PHP', 'C#', 'Python', 'C', 'Java', 'C++'])]
Time Complexity: O(1) – The time complexity of importing a module is considered constant time.
Auxiliary Space: O(1) – The original array and split array are both stored in memory, which does not change with the size of the input. Therefore, the auxiliary space is constant.
['Geeks For Geeks'] [list(['Geeks', 'For', 'Geeks'])]
Time complexity: O(n), where n is the length of the input array.
Auxiliary space: O(n), where n is the length of the input array.
['DBMS OOPS DS'] [list(['DBMS', 'OOPS', 'DS'])]
The time complexity of the code is O(n), where n is the length of the input string.
The auxiliary space complexity of the code is O(n),
Please Login to comment...