Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
communitycreator

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

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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))
Implementing the char.rpartition() function

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.

RELATED TAGS

python
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring