![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Return a list of the lines in the element, breaking at line boundaries in Numpy
To return a list of the lines in the element, breaking at line boundaries, use the numpy.char.splitlines() method in Python Numpy. The 1st parameter is the input array.
The keepends parameter suggests that the Line breaks are not included in the resulting list unless keepends is given and true. The function splitlines() 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...
",arr)
Get the datatype −
print("
Array datatype...
",arr.dtype)
Get the dimensions of the Array −
print("
Array Dimensions...
",arr.ndim)
Get the shape of the Array −
print("
Our Array Shape...
",arr.shape)
Get the number of elements of the Array −
print("
Elements in the Array...
",arr.size)
To return a list of the lines in the element, breaking at line boundaries, use the numpy.char.splitlines() method −
print("
Result...
",np.char.splitlines(arr))
Example
import numpy as np # Create an array arr = np.array(["Bella
Cio", "Brad
Pitt", "Katie
Perry"]) # Displaying our Array print("Array...
",arr) # Get the datatype print("
Array datatype...
",arr.dtype) # Get the dimensions of the Array print("
Array Dimensions...
",arr.ndim) # Get the shape of the Array print("
Our Array Shape...
",arr.shape) # Get the number of elements of the Array print("
Elements in the Array...
",arr.size) # To return a list of the lines in the element, breaking at line boundaries, use the numpy.char.splitlines() method in Python Numpy # The 1st parameter is the input array print("
Result...
",np.char.splitlines(arr))
Output
Array... ['Bella
Cio' 'Brad
Pitt' 'Katie
Perry'] 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'])]