Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
communitycreator

What is the numpy.char.join() 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.join() function in Python’s NumPy library is used to concatenate an array of strings in a given sequence seq. The char.join() function returns a string in which each of the array elements is joined by a specified separator character.

Syntax

char.join(sep, seq)

Function parameters

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

  • sep: This represents the array of strings or unicodes that will be used as the separator characters.
  • seq: This represents the input array that needs to be concatenated.

Return value

The char.join() function returns an array of strings or unicodes.

Code example

import numpy as np
# creating an array string to be concatenated
myarray = np.array(['Apple', 'Python', 'NumPy','Educative'])
print ("The Input array : \n", myarray)
# creating the seperator characters
separray = np.array(['__'])
print ("\n")
newarray= np.char.join(separray, myarray)
print ("The concatenated array: \n", newarray)
Implementing the "char.join()" function

Code explanation

  • Line 1: We import the numpy module.
  • Line 4: We create the input array, myarray, using the array() function.
  • Line 5: We print the array called myarray.
  • Line 8: We create the separator array, separray, using the array() function.
  • Line 12: We implement the char.join() function on both the arrays. Then, we assign the result to another variable called newarray.
  • Line 14: We print the variable newarray to the console.

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