# Return a list of the words in the string using separator as the delimiter string in Numpy

NumpyServer Side ProgrammingProgramming

#### Python Data Science basics with Numpy, Pandas and Matplotlib

Most Popular

63 Lectures 6 hours

#### Data Analysis using NumPy and Pandas

19 Lectures 8 hours

#### Numpy with Python

Most Popular

12 Lectures 3 hours

To return a list of the words in the string using separator as the delimiter string, use the numpy.char.split() method in Python Numpy −

• The 1st parameter is the input array
• The 2nd parameter is the separator

If maxsplit parameter is given, at most maxsplit splits are done. The function split() returns an array of list objects.

The numpy.char module provides a set of vectorized string operations for arrays of type numpy.str_ or numpy.bytes_.

## Steps

At first, import the required library −

import numpy as np

Create an array −

arr = np.array(["Bella-Cio", "Brad-Pitt", "Katie-Perry"])

Displaying our array −

print("Array...\n",arr)

Get the datatype −

print("\nArray datatype...\n",arr.dtype)


Get the dimensions of the Array −

print("\nArray Dimensions...\n",arr.ndim)

Get the shape of the Array −

print("\nOur Array Shape...\n",arr.shape)

Get the number of elements of the Array −

print("\nElements in the Array...\n",arr.size)

To return a list of the words in the string using separator as the delimiter string, use the numpy.char.split() method −

print("\nResult...\n",np.char.split(arr, '-'))


## Example

import numpy as np

# Create an array
arr = np.array(["Bella-Cio", "Brad-Pitt", "Katie-Perry"])

# Displaying our Array
print("Array...\n",arr)

# Get the datatype
print("\nArray datatype...\n",arr.dtype)

# Get the dimensions of the Array
print("\nArray Dimensions...\n",arr.ndim)

# Get the shape of the Array
print("\nOur Array Shape...\n",arr.shape)

# Get the number of elements of the Array
print("\nElements in the Array...\n",arr.size)

# To return a list of the words in the string using separator as the delimiter string, use the numpy.char.split() method in Python Numpy
# The 1st parameter is the input array
# The 2nd parameter is the separator
print("\nResult...\n",np.char.split(arr, '-'))

## Output

Array...

Array datatype...
<U11

Array Dimensions...
1

Our Array Shape...
(3,)

Elements in the Array...
3

Result...
[list(['Bella', 'Cio']) list(['Brad', 'Pitt']) list(['Katie', 'Perry'])]