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

Overview

In Python, the char.rpartition() is used to split each element of an array of strings around the right-most separator.

Syntax

char.rpartition(a, sep)

Parameter value

This function takes the following parameter values:

  • a: This is the input array of strings or Unicode.
  • sep: This is the right-most separator to split each element in the given array.

Return value

This function returns an array of strings or unicode, depending on the input type in the function.

import numpy as np
# creating the input array
a = np.array(["Hi what are your doing?"])
# creating seperator character
sep = "your"
# implementing the char.rpartition() function
print(np.char.rpartition(a, sep))

Explanation

  • Line 1: We import the numpy module.
  • Line 4: We use the array() function to create an array of strings myarray.
  • Line 7: We create a separator variable sep that we use to partition the elements in the array.
  • Line 10: We implement the char.rpartition() function on the variables myarray and sep. Next, we obtain and print the result.