NumPy ndarray: Difference between revisions
Line 3: | Line 3: | ||
=Overview= | =Overview= | ||
<code>ndarray</code> is an N-dimensional array object. It is a fast, flexible container for large datasets in Python. It is used to implement a Pandas [[Pandas_Series#Overview|Series]]. It allows performing mathematical operations on whole blocks of data using similar syntax to the equivalent operation between scalar elements. <code>ndarray</code>s are homogeneous, all elements of an <code>ndarray</code> instance have the same [[#Data_Type|data type]]. <code>ndarray</code>s can be created by [[#Convert_Python_Data_Structures|converting Python data structures]], using [[NumPy_ndarray#With_Generators|generators]], or [[#By_Specifying_Shape_and_Value|initializing blocks of memory of specified shape with specified values]]. | <code>ndarray</code> is an N-dimensional array object. It is a fast, flexible container for large datasets in Python. It is used to implement a Pandas [[Pandas_Series#Overview|Series]]. It allows performing mathematical operations on whole blocks of data using similar syntax to the equivalent operation between scalar elements. <code>ndarray</code>s are homogeneous, all elements of an <code>ndarray</code> instance have the same [[#Data_Type|data type]]. <code>ndarray</code>s can be created by [[#Convert_Python_Data_Structures|converting Python data structures]], using [[NumPy_ndarray#With_Generators|generators]], or [[#By_Specifying_Shape_and_Value|initializing blocks of memory of specified shape with specified values]]. | ||
=<tt>ndarray</tt> Geometry= | |||
=<tt>ndarray</tt> Creation= | =<tt>ndarray</tt> Creation= |
Revision as of 19:39, 20 May 2024
Internal
Overview
ndarray
is an N-dimensional array object. It is a fast, flexible container for large datasets in Python. It is used to implement a Pandas Series. It allows performing mathematical operations on whole blocks of data using similar syntax to the equivalent operation between scalar elements. ndarray
s are homogeneous, all elements of an ndarray
instance have the same data type. ndarray
s can be created by converting Python data structures, using generators, or initializing blocks of memory of specified shape with specified values.
ndarray Geometry
ndarray Creation
Convert Python Data Structures
The np.array()
function takes Python data structures, such as lists, lists of list, tuples, etc. and generates the corresponding shape ndarray
. For example, a bi-dimensional 3 x 3 ndarray
can be created by providing a list of 3 lists, each of the enclosed lists containing 3 elements:
import numpy as np
a = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
array([[1, 2, 3],
[4, 5, 6], [7, 8, 9]])