Numpy字符串操作 |分割线()函数
在这个numpy.core.defchararray.splitlines()函数中,arr 中的每个元素都返回元素中的行列表,在行边界处中断。
Syntax : numpy.core.defchararray.splitlines(arr, keepends = None)
Parameters :
arr : [array-like of str] Given array-like of string.
keepends : [bool, optional] Line breaks are not included in the resulting list unless keepends is given and true.
Return : [ndarray] Return the Array of list objects.
代码#1:
Python3
# Python program explaining
# numpy.char.splitlines() function
# importing numpy as geek
import numpy as geek
gfg = geek.char.splitlines('GeeksforGeeks \n A computer science portal \n for geeks')
print (gfg)
Python3
# Python program explaining
# numpy.char.splitlines() function
# importing numpy as geek
import numpy as geek
gfg = geek.char.splitlines('This is \r a Python-Numpy \r article \r for geeks')
print (gfg)
输出 :
[‘GeeksforGeeks ‘, ‘ A computer science portal ‘, ‘ for geeks’]
代码#2:
Python3
# Python program explaining
# numpy.char.splitlines() function
# importing numpy as geek
import numpy as geek
gfg = geek.char.splitlines('This is \r a Python-Numpy \r article \r for geeks')
print (gfg)
输出 :
[‘This is ‘, ‘ a Python-Numpy ‘, ‘ article ‘, ‘ for geeks’]