The char.partition()
function in Python is used to partition each element in an input array using a separator.
char.partition(a, sep)
The char.partition()
function takes the following parameter values:
a
: Represents the input array.sep
: Represents the separator used to split the elements in the input array.The char.partition()
function returns an array of strings or Unicode, depending on the input type in the input array.
import numpy as np# creating an array of stringsmyarray = np.array(["This is my house"])# creating separator charactersep ='my'# Implementing the char.partition() function and printing our result.print(np.char.partition(myarray, sep))
numpy
module.myarray
using the array()
function.sep
that we use to partition the elements in the array.np.char.partition()
function on the variables myarray
and sep
, and print the result.