What is the numpy.char.rsplit() function in Python?

Overview

The numpy.char.rsplit() function in Python is used to return a list of words in the string of an array of strings using a sep as the delimiter string.

Syntax

char.rsplit(a, sep=None)

Parameter value

The numpy.char.rsplit() function takes the following parameter values:

  • a: This is the input array of strings or Unicode.
  • sep: This is the delimiter string or the separator. If this value is not specified, then a whitespace string is used as a separator.
  • maxsplit: This represents the maximum split that can be done. This parameter value is optional.

Return value

The numpy.char.rsplit() function returns an array of list objects.

Code example

import numpy as np
# creating an input array
a = np.array(['Artery', 'Material', 'Arterial'])
myarray= np.char.rsplit(a, sep ="er")
print(myarray)

Code explanation

  • Line 1: We import the numpy module.
  • Line 4: We create an array of strings, a, using the array() function.
  • Line 6: We implement the char.rsplit() function on the array a and assign the result to a variable called myarray.
  • Line 8: We print the array myarray.

Free Resources