numpy array split function code example
Example 1: numpy split
"1-D Array For example, [2, 3] would, for axis=0, result in
ary[:2]
ary[2:3]
ary[3:]
Example 2: split string with numpy python
# Split string inside numpay array
import numpy as np
# In this case I want to remove everything before " – "
# to stay only with --> "I have a friendly staff", "Friendly staff advice for..."
array = ['Linda Rodway – I have a friendly staff',
'Kevin Ransom – Friendly staff advice for...']
# Create numpy array
a = np.array(array)
# Now you can split using .split method and loop through all inside a
b = np.array([x.split(' – ')[1] for x in a])
# in this case if you remove [1] you will see the following result:
# 'Linda Rodway', 'I have a friendly staff', and you use [1] to show only
# the second one 'I have a friendly staff'