- Trending Categories
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
Construct a record array from a wide-variety of objects in Numpy
To display the numpy record array, use the numpy.core.records.array() method in Python Numpy. The 1st parameter is the obj i.e. the input. If obj is None, then call the recarray constructor. If obj is a string, then call the fromstring constructor. If obj is a list or a tuple, then if the first object is an ndarray, call fromarrays, otherwise call fromrecords. If obj is a recarray, then make a copy of the data in the recarray (if copy=True) and use the new formats, names, and titles. If obj is a file, then call fromfile. Finally, if obj is an ndarray, then return obj.view(recarray), making a copy of the data if copy=True.
Steps
At first, import the required library −
import numpy as np
Create a new array using the numpy.array() method −
arr = np.array([[5, 10, 15], [20, 25, 30], [35, 40, 45], [50, 55, 60]])
Display the array −
print("Array...
",arr)
Get the type of the array −
print("
Array type...
", arr.dtype)
Get the dimensions of the Array: −
print("
Array Dimensions...
", arr.ndim)
To display the numpy record array, use the numpy.core.records.array() method in Python Numpy −
print("
Record Array...
",np.core.records.array(arr))
Example
import numpy as np # Create a new array using the numpy.array() method arr = np.array([[5, 10, 15], [20, 25, 30], [35, 40, 45], [50, 55, 60]]) # Display the array print("Array...
",arr) # Get the type of the array print("
Array type...
", arr.dtype) # Get the dimensions of the Array print("
Array Dimensions...
", arr.ndim) # To display the numpy record array, use the numpy.core.records.array() method in Python Numpy print("
Record Array...
",np.core.records.array(arr))
Output
Array... [[ 5 10 15] [20 25 30] [35 40 45] [50 55 60]] Array type... int64 Array Dimensions... 2 Record Array... [[ 5 10 15] [20 25 30] [35 40 45] [50 55 60]]
- Related Articles
- Create a record array from a (flat) list of array in Numpy
- Create a record array from binary data in Numpy
- Create a record array from a (flat) list of array and fetch arrays using names in Numpy
- Use an index array to construct a new array from a set of choices in Numpy
- Create a record array from a (flat) list of array and set a valid datatype for all in Numpy
- Create a record array from a (flat) list of array and fetch specific values based on index in Numpy
- Use an index array to construct a new array from a set of choices with clip mode in Numpy
- Use an index array to construct a new array from a set of choices with wrap mode in Numpy
- Construct an array by executing a function over each coordinate in Numpy
- Remove duplicates from a array of objects JavaScript
- Add all records from one array to each record from a different array in JavaScript
- Extract a property from an array of objects in PHP
- Python Pandas - Return numpy array of python datetime.date objects
- Python Pandas - Return numpy array of python datetime.time objects
- Construct objects from joining two strings JavaScript
