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.
char.join(sep, seq)
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.The char.join()
function returns an array of strings or unicodes.
import numpy as np# creating an array string to be concatenatedmyarray = np.array(['Apple', 'Python', 'NumPy','Educative'])print ("The Input array : \n", myarray)# creating the seperator charactersseparray = np.array(['__'])print ("\n")newarray= np.char.join(separray, myarray)print ("The concatenated array: \n", newarray)
numpy
module.myarray
, using the array()
function.myarray
.separray
, using the array()
function.char.join()
function on both the arrays. Then, we assign the result to another variable called newarray
.newarray
to the console.