Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
communitycreator

What is the numpy.char.add() 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.add() function in Python is simply used to return an element-wise string concatenation of two arrays, str, or Unicode.

Syntax

char.add(x1, x2)

Parameter value

The char.add() function takes the following mandatory parameter values.

  • x1: This represents the input array.
  • x2: This represents the second input array to be concatenated with the first input array.

Return value

The char.add() function returns an array of strins or unicodes.

Code

import numpy as np
# creatin the arrays
x1 = ['Hi', 'Welcome', 'board']
x2 = ['Pals', 'on', '!']
# implementing the char.add() method
myarray = np.char.add(x1, x2)
print(myarray)
Implementing the char.add() function

Explanation

  • Line 1: We import the numpy module.
  • Lines 4-5: We create array variables x1 and x2.
  • Line 8: We use the char.add() function to concatenate the arrays, x1 and x2. The result is assigned to a variable myarray.
  • Line 8: We print the variable myarray.

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