Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

function
python
numpy
communitycreator

What is the numpy.rjust() function from NumPy 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

The char.rjust() function in Python is used to return an array with the length of an input array that is right-justified in a string of a given length.

Syntax

char.rjust(a, width, fillchar=' ')

Parameter

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

  • a: This represents the input array.
  • width: This represents the length of the output string.
  • fillchar: This represents the character that is used for padding.

Return value

The char.rjust() function returns an array of strings or Unicode. The returned value depends on the input type in the function.

Example

Let’s look at the code below:

import numpy as np

# implementing the char.rjust() function 
myarray = np.char.rjust('Theo', 10, fillchar = '*')

print(myarray)
Implementing the char.rjust() function

Explanation

  • Line 4: We create a string character called "Theo". Then, we choose to return an array of string with a length of 10, which is to be filled with the character "*" at a particular number of times just before "Theo" is added. It makes the resulting array a total length of 10 characters.

RELATED TAGS

function
python
numpy
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