The NumPy array object is a core data structure provided by the NumPy library. It is also known as ndarray which stands for N‒dimensional array.
NumPy
Array Objects
•
The NumPy array object is a core data structure provided by the NumPy library.
It is also known as ndarray which
stands for N‒dimensional array.
Structure
of NumPy array object(ndarray) is
Component : Purpose
data
‒ The actual values stored. It can be numbers, strings.
shape
‒ The dimension of array(rows * columns)
dtype
‒ It is basically the data type of elements in the memory.
strides
‒ Steps to move through elements in memory.
flags
‒ Internal information about memory and storage
Python
program for creation of NumPy array object
import numpy as np
arr = np.array([10,20,30,40,50])
print(arr)
print(type(arr))
Output.
[10 20 30 40 50]
<class
'numpy.ndarray'>
Code explanation:
In above code,
We
have created an array object arr. It
stores 5 integers. The values are stored in continuous memory allowing fast
mathematical operations. Note that in the output we get the type of array as <class 'numpy.ndarray">
which indicates that it is an object,
Python
program for creating 2D array object
import numpy as np
arr = np.array([[10,20,30],[40,50,60]])
print(arr)
print(type(arr))
[[10 20 30]
[40 50 60]]
<class
'numpy.ndarray'>
Code explanation:
In above code,
The
2D Numpy array object is created in variable arr. It has 2 rows and 3 columns. The type returns the datatype of
variable arr and it is ndarray. This is nothing but the array
object.
1) Homogeneous:
All the elements are of same type. For instance ‒ All the elements in array can
be integers.
2) Efficient storage:
The NumPy arrays use less memory than Python lists.
3) Vectorized operations:
It allows element ‒ wise computations such as arr1+arr2 or arrl‒arr2.
4) Multidimensional:
We can create 1D, 2D, 3D arrays
5) Attribute support:
The array objects can use various attributes such as shape, size, type and so
on.
1. What is the class
name of a NumPy array object?
Python for Data Science: Chapter 5: NumPy and Pandas Libraries : Tag: Computer Programming, Python, Data Science : Python library - NumPy Array Objects
Python for Data Science
AD25201 2nd Semester AIDS Dept | 2025 Regulation | 2nd Semester 2025 Regulation
English Essentials II
EN25C02 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Tamils and Technology தமிழர்களும் தொழில்நுட்பமும்
UC25H02 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Linear Algebra
MA25C02 2nd Semester | 2025 Regulation
Applied Physics (CSIE) II
PH25C03 2nd Semester AIDS, CSE, IT, CSE(CY) Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Digital Principles and Computer Organization
CS25C06 2nd Semester AIDS, CSE, IT, CSE(CY) Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Basic Electrical and Electronics Engineering
EE25C01 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Python for Data Science
AD25201 2nd Semester AIDS Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Re-Engineering for Innovation
ME25C05 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Python for Data Science - Laboratory
AD25201 2nd Semester AIDS Dept | 2025 Regulation | 2nd Semester 2025 Regulation