SlideShare a Scribd company logo
2
PythonForDataScience Cheat Sheet
NumPy Basics
Learn Python for Data Science Interactively at www.DataCamp.com
NumPy
DataCamp
Learn Python for Data Science Interactively
The NumPy library is the core library for scientific computing in
Python. It provides a high-performance multidimensional array
object, and tools for working with these arrays.
>>> import numpy as np
Use the following import convention:
Creating Arrays
>>> np.zeros((3,4)) Create an array of zeros
>>> np.ones((2,3,4),dtype=np.int16) Create an array of ones
>>> d = np.arange(10,25,5) Create an array of evenly
spaced values (step value)
>>> np.linspace(0,2,9) Create an array of evenly
spaced values (number of samples)
>>> e = np.full((2,2),7) Create a constant array
>>> f = np.eye(2) Create a 2X2 identity matrix
>>> np.random.random((2,2)) Create an array with random values
>>> np.empty((3,2)) Create an empty array
Array Mathematics
>>> g = a - b Subtraction
array([[-0.5, 0. , 0. ],
[-3. , -3. , -3. ]])
>>> np.subtract(a,b) Subtraction
>>> b + a Addition
array([[ 2.5, 4. , 6. ],
[ 5. , 7. , 9. ]])
>>> np.add(b,a) Addition
>>> a / b Division
array([[ 0.66666667, 1. , 1. ],
[ 0.25 , 0.4 , 0.5 ]])
>>> np.divide(a,b) Division
>>> a * b Multiplication
array([[ 1.5, 4. , 9. ],
[ 4. , 10. , 18. ]])
>>> np.multiply(a,b) Multiplication
>>> np.exp(b) Exponentiation
>>> np.sqrt(b) Square root
>>> np.sin(a) Print sines of an array
>>> np.cos(b) Element-wise cosine
>>> np.log(a) Element-wise natural logarithm
>>> e.dot(f) Dot product
array([[ 7., 7.],
[ 7., 7.]])
Subsetting, Slicing, Indexing
>>> a.sum() Array-wise sum
>>> a.min() Array-wise minimum value
>>> b.max(axis=0) Maximum value of an array row
>>> b.cumsum(axis=1) Cumulative sum of the elements
>>> a.mean() Mean
>>> b.median() Median
>>> a.corrcoef() Correlation coefficient
>>> np.std(b) Standard deviation
Comparison
>>> a == b Element-wise comparison
array([[False, True, True],
[False, False, False]], dtype=bool)
>>> a < 2 Element-wise comparison
array([True, False, False], dtype=bool)
>>> np.array_equal(a, b) Array-wise comparison
1 2 3
1D array 2D array 3D array
1.5 2 3
4 5 6
Array Manipulation
NumPy Arrays
axis 0
axis 1
axis 0
axis 1
axis 2
Arithmetic Operations
Transposing Array
>>> i = np.transpose(b) Permute array dimensions
>>> i.T Permute array dimensions
Changing Array Shape
>>> b.ravel() Flatten the array
>>> g.reshape(3,-2) Reshape, but don’t change data
Adding/Removing Elements
>>> h.resize((2,6)) Return a new array with shape (2,6)
>>> np.append(h,g) Append items to an array
>>> np.insert(a, 1, 5) Insert items in an array
>>> np.delete(a,[1]) Delete items from an array
Combining Arrays
>>> np.concatenate((a,d),axis=0) Concatenate arrays
array([ 1, 2, 3, 10, 15, 20])
>>> np.vstack((a,b)) Stack arrays vertically (row-wise)
array([[ 1. , 2. , 3. ],
[ 1.5, 2. , 3. ],
[ 4. , 5. , 6. ]])
>>> np.r_[e,f] Stack arrays vertically (row-wise)
>>> np.hstack((e,f)) Stack arrays horizontally (column-wise)
array([[ 7., 7., 1., 0.],
[ 7., 7., 0., 1.]])
>>> np.column_stack((a,d)) Create stacked column-wise arrays
array([[ 1, 10],
[ 2, 15],
[ 3, 20]])
>>> np.c_[a,d] Create stacked column-wise arrays
Splitting Arrays
>>> np.hsplit(a,3) Split the array horizontally at the 3rd
[array([1]),array([2]),array([3])] index
>>> np.vsplit(c,2) Split the array vertically at the 2nd index
[array([[[ 1.5, 2. , 1. ],
[ 4. , 5. , 6. ]]]),
array([[[ 3., 2., 3.],
[ 4., 5., 6.]]])]
Also see Lists
Subsetting
>>> a[2] Select the element at the 2nd index
3
>>> b[1,2] Select the element at row 1 column 2
6.0 (equivalent to b[1][2])
Slicing
>>> a[0:2] Select items at index 0 and 1
array([1, 2])
>>> b[0:2,1] Select items at rows 0 and 1 in column 1
array([ 2., 5.])
>>> b[:1] Select all items at row 0
array([[1.5, 2., 3.]]) (equivalent to b[0:1, :])
>>> c[1,...] Same as [1,:,:]
array([[[ 3., 2., 1.],
[ 4., 5., 6.]]])
>>> a[ : :-1] Reversed array a
array([3, 2, 1])
Boolean Indexing
>>> a[a<2] Select elements from a less than 2
array([1])
Fancy Indexing
>>> b[[1, 0, 1, 0],[0, 1, 2, 0]] Select elements (1,0),(0,1),(1,2)and (0,0)
array([ 4. , 2. , 6. , 1.5])
>>> b[[1, 0, 1, 0]][:,[0,1,2,0]] Select a subset of the matrix’s rows
array([[ 4. ,5. , 6. , 4. ], and columns
[ 1.5, 2. , 3. , 1.5],
[ 4. , 5. , 6. , 4. ],
[ 1.5, 2. , 3. , 1.5]])
>>> a = np.array([1,2,3])
>>> b = np.array([(1.5,2,3), (4,5,6)], dtype = float)
>>> c = np.array([[(1.5,2,3), (4,5,6)], [(3,2,1), (4,5,6)]],
dtype = float)
Initial Placeholders
Aggregate Functions
>>> np.loadtxt("myfile.txt")
>>> np.genfromtxt("my_file.csv", delimiter=',')
>>> np.savetxt("myarray.txt", a, delimiter=" ")
I/O
1 2 3
1.5 2 3
4 5 6
Copying Arrays
>>> h = a.view() Create a view of the array with the same data
>>> np.copy(a) Create a copy of the array
>>> h = a.copy() Create a deep copy of the array
Saving & Loading Text Files
Saving & Loading On Disk
>>> np.save('my_array', a)
>>> np.savez('array.npz', a, b)
>>> np.load('my_array.npy')
>>> a.shape Array dimensions
>>> len(a) Length of array
>>> b.ndim Number of array dimensions
>>> e.size Number of array elements
>>> b.dtype Data type of array elements
>>> b.dtype.name Name of data type
>>> b.astype(int) Convert an array to a different type
Inspecting Your Array
>>> np.info(np.ndarray.dtype)
Asking For Help
Sorting Arrays
>>> a.sort() Sort an array
>>> c.sort(axis=0) Sort the elements of an array's axis
Data Types
>>> np.int64 Signed 64-bit integer types
>>> np.float32 Standard double-precision floating point
>>> np.complex Complex numbers represented by 128 floats
>>> np.bool Boolean type storing TRUE and FALSE values
>>> np.object Python object type
>>> np.string_ Fixed-length string type
>>> np.unicode_ Fixed-length unicode type
1 2 3
1.5 2 3
4 5 6
1.5 2 3
4 5 6
1 2 3

More Related Content

What's hot (20)

PPTX
Data Structures in Python
Devashish Kumar
 
PDF
Introduction to Python Pandas for Data Analytics
Phoenix
 
PDF
Pandas Cheat Sheet
ACASH1011
 
PPTX
Python list
ArchanaBhumkar
 
PPTX
Introduction to pandas
Piyush rai
 
PPTX
Python & jupyter notebook installation
Anamta Sayyed
 
PPTX
Data visualization using R
Ummiya Mohammedi
 
PDF
Cheat Sheet for Machine Learning in Python: Scikit-learn
Karlijn Willems
 
PPTX
MySQL Basics
mysql content
 
PDF
Python Sequence | Python Lists | Python Sets & Dictionary | Python Strings | ...
Edureka!
 
PDF
pandas: Powerful data analysis tools for Python
Wes McKinney
 
PPTX
Basic Analysis using Python
Sankhya_Analytics
 
PPTX
Pandas
Jyoti shukla
 
PPTX
Data Analysis with Python Pandas
Neeru Mittal
 
PPTX
Introduction to numpy
Gaurav Aggarwal
 
PPTX
Python decorators
Alex Su
 
PDF
List , tuples, dictionaries and regular expressions in python
channa basava
 
PDF
Python seaborn cheat_sheet
Nishant Upadhyay
 
PPTX
Python pandas Library
Md. Sohag Miah
 
PDF
Advanced data structures vol. 1
Christalin Nelson
 
Data Structures in Python
Devashish Kumar
 
Introduction to Python Pandas for Data Analytics
Phoenix
 
Pandas Cheat Sheet
ACASH1011
 
Python list
ArchanaBhumkar
 
Introduction to pandas
Piyush rai
 
Python & jupyter notebook installation
Anamta Sayyed
 
Data visualization using R
Ummiya Mohammedi
 
Cheat Sheet for Machine Learning in Python: Scikit-learn
Karlijn Willems
 
MySQL Basics
mysql content
 
Python Sequence | Python Lists | Python Sets & Dictionary | Python Strings | ...
Edureka!
 
pandas: Powerful data analysis tools for Python
Wes McKinney
 
Basic Analysis using Python
Sankhya_Analytics
 
Pandas
Jyoti shukla
 
Data Analysis with Python Pandas
Neeru Mittal
 
Introduction to numpy
Gaurav Aggarwal
 
Python decorators
Alex Su
 
List , tuples, dictionaries and regular expressions in python
channa basava
 
Python seaborn cheat_sheet
Nishant Upadhyay
 
Python pandas Library
Md. Sohag Miah
 
Advanced data structures vol. 1
Christalin Nelson
 

Similar to Numpy python cheat_sheet (20)

PDF
Numpy_Cheat_Sheet.pdf
SkyNerve
 
PPTX
NUMPY LIBRARY study materials PPT 2.pptx
CHETHANKUMAR274045
 
PDF
Numpy cheat-sheet
Arief Kurniawan
 
PPTX
Numpy in python, Array operations using numpy and so on
SherinRappai
 
PPTX
Data Preprocessing Introduction for Machine Learning
sonali sonavane
 
PPTX
NumPy-python-27-9-24-we.pptxNumPy-python-27-9-24-we.pptx
tahirnaquash2
 
PDF
ACFrOgAabSLW3ZCRLJ0i-To_2fPk_pA9QThyDKNNlA3VK282MnXaLGJa7APKD15-TW9zT_QI98dAH...
DineshThallapelly
 
PPTX
NUMPY [Autosaved] .pptx
coolmanbalu123
 
PPTX
Arrays with Numpy, Computer Graphics
Prabu U
 
PDF
Introduction to NumPy (PyData SV 2013)
PyData
 
PDF
Introduction to NumPy
Huy Nguyen
 
PDF
Essential numpy before you start your Machine Learning journey in python.pdf
Smrati Kumar Katiyar
 
PPT
CAP776Numpy (2).ppt
ChhaviCoachingCenter
 
PPT
CAP776Numpy.ppt
kdr52121
 
PDF
CE344L-200365-Lab2.pdf
UmarMustafa13
 
PPTX
Numpy_defintion_description_usage_examples.pptx
VGaneshKarthikeyan
 
PPTX
NUMPY-2.pptx
MahendraVusa
 
PPTX
lec08-numpy.pptx
lekha572836
 
PPTX
UNIT-03_Numpy (1) python yeksodbbsisbsjsjsh
tony8553004135
 
PDF
numpy.pdf
ssuser457188
 
Numpy_Cheat_Sheet.pdf
SkyNerve
 
NUMPY LIBRARY study materials PPT 2.pptx
CHETHANKUMAR274045
 
Numpy cheat-sheet
Arief Kurniawan
 
Numpy in python, Array operations using numpy and so on
SherinRappai
 
Data Preprocessing Introduction for Machine Learning
sonali sonavane
 
NumPy-python-27-9-24-we.pptxNumPy-python-27-9-24-we.pptx
tahirnaquash2
 
ACFrOgAabSLW3ZCRLJ0i-To_2fPk_pA9QThyDKNNlA3VK282MnXaLGJa7APKD15-TW9zT_QI98dAH...
DineshThallapelly
 
NUMPY [Autosaved] .pptx
coolmanbalu123
 
Arrays with Numpy, Computer Graphics
Prabu U
 
Introduction to NumPy (PyData SV 2013)
PyData
 
Introduction to NumPy
Huy Nguyen
 
Essential numpy before you start your Machine Learning journey in python.pdf
Smrati Kumar Katiyar
 
CAP776Numpy (2).ppt
ChhaviCoachingCenter
 
CAP776Numpy.ppt
kdr52121
 
CE344L-200365-Lab2.pdf
UmarMustafa13
 
Numpy_defintion_description_usage_examples.pptx
VGaneshKarthikeyan
 
NUMPY-2.pptx
MahendraVusa
 
lec08-numpy.pptx
lekha572836
 
UNIT-03_Numpy (1) python yeksodbbsisbsjsjsh
tony8553004135
 
numpy.pdf
ssuser457188
 
Ad

More from Nishant Upadhyay (13)

PDF
Multivariate calculus
Nishant Upadhyay
 
PDF
Multivariate calculus
Nishant Upadhyay
 
PDF
Matrices1
Nishant Upadhyay
 
PDF
Vectors2
Nishant Upadhyay
 
PDF
Mathematics for machine learning calculus formulasheet
Nishant Upadhyay
 
PDF
Pandas pythonfordatascience
Nishant Upadhyay
 
PDF
Maths4ml linearalgebra-formula
Nishant Upadhyay
 
PDF
Sqlcheetsheet
Nishant Upadhyay
 
PDF
Sql cheat-sheet
Nishant Upadhyay
 
PDF
My sql installationguide_windows
Nishant Upadhyay
 
PDF
Company handout
Nishant Upadhyay
 
PDF
Python bokeh cheat_sheet
Nishant Upadhyay
 
PDF
Foliumcheatsheet
Nishant Upadhyay
 
Multivariate calculus
Nishant Upadhyay
 
Multivariate calculus
Nishant Upadhyay
 
Matrices1
Nishant Upadhyay
 
Mathematics for machine learning calculus formulasheet
Nishant Upadhyay
 
Pandas pythonfordatascience
Nishant Upadhyay
 
Maths4ml linearalgebra-formula
Nishant Upadhyay
 
Sqlcheetsheet
Nishant Upadhyay
 
Sql cheat-sheet
Nishant Upadhyay
 
My sql installationguide_windows
Nishant Upadhyay
 
Company handout
Nishant Upadhyay
 
Python bokeh cheat_sheet
Nishant Upadhyay
 
Foliumcheatsheet
Nishant Upadhyay
 
Ad

Recently uploaded (20)

PDF
Orchestrating Data Workloads With Airflow.pdf
ssuserae5511
 
PDF
Kafka Use Cases Real-World Applications
Accentfuture
 
PDF
A Web Repository System for Data Mining in Drug Discovery
IJDKP
 
PDF
624753984-Annex-A3-RPMS-Tool-for-Proficient-Teachers-SY-2024-2025.pdf
CristineGraceAcuyan
 
DOCX
brigada_PROGRAM_25.docx the boys white house
RonelNebrao
 
PPTX
Monitoring Improvement ( Pomalaa Branch).pptx
fajarkunee
 
PDF
Digital-Transformation-for-Federal-Agencies.pdf.pdf
One Federal Solution
 
PPTX
english9quizw1-240228142338-e9bcf6fd.pptx
rossanthonytan130
 
PPTX
Data Analytics using sparkabcdefghi.pptx
KarkuzhaliS3
 
PPTX
Communication_Skills_Class10_Visual.pptx
namanrastogi70555
 
PDF
11_L2_Defects_and_Trouble_Shooting_2014[1].pdf
gun3awan88
 
PPTX
ppt somu_Jarvis_AI_Assistant_presen.pptx
MohammedumarFarhan
 
PPSX
PPT1_CB_VII_CS_Ch3_FunctionsandChartsinCalc.ppsx
animaroy81
 
PDF
CT-2-Ancient ancient accept-Criticism.pdf
DepartmentofEnglishC1
 
PPTX
Indigo dyeing Presentation (2).pptx as dye
shreeroop1335
 
DOCX
COT Feb 19, 2025 DLLgvbbnnjjjjjj_Digestive System and its Functions_PISA_CBA....
kayemorales1105
 
PDF
Informatics Market Insights AI Workforce.pdf
karizaroxx
 
PPTX
一比一原版(TUC毕业证书)开姆尼茨工业大学毕业证如何办理
taqyed
 
PDF
Data science AI/Ml basics to learn .pdf
deokhushi04
 
PDF
TCU EVALUATION FACULTY TCU Taguig City 1st Semester 2017-2018
MELJUN CORTES
 
Orchestrating Data Workloads With Airflow.pdf
ssuserae5511
 
Kafka Use Cases Real-World Applications
Accentfuture
 
A Web Repository System for Data Mining in Drug Discovery
IJDKP
 
624753984-Annex-A3-RPMS-Tool-for-Proficient-Teachers-SY-2024-2025.pdf
CristineGraceAcuyan
 
brigada_PROGRAM_25.docx the boys white house
RonelNebrao
 
Monitoring Improvement ( Pomalaa Branch).pptx
fajarkunee
 
Digital-Transformation-for-Federal-Agencies.pdf.pdf
One Federal Solution
 
english9quizw1-240228142338-e9bcf6fd.pptx
rossanthonytan130
 
Data Analytics using sparkabcdefghi.pptx
KarkuzhaliS3
 
Communication_Skills_Class10_Visual.pptx
namanrastogi70555
 
11_L2_Defects_and_Trouble_Shooting_2014[1].pdf
gun3awan88
 
ppt somu_Jarvis_AI_Assistant_presen.pptx
MohammedumarFarhan
 
PPT1_CB_VII_CS_Ch3_FunctionsandChartsinCalc.ppsx
animaroy81
 
CT-2-Ancient ancient accept-Criticism.pdf
DepartmentofEnglishC1
 
Indigo dyeing Presentation (2).pptx as dye
shreeroop1335
 
COT Feb 19, 2025 DLLgvbbnnjjjjjj_Digestive System and its Functions_PISA_CBA....
kayemorales1105
 
Informatics Market Insights AI Workforce.pdf
karizaroxx
 
一比一原版(TUC毕业证书)开姆尼茨工业大学毕业证如何办理
taqyed
 
Data science AI/Ml basics to learn .pdf
deokhushi04
 
TCU EVALUATION FACULTY TCU Taguig City 1st Semester 2017-2018
MELJUN CORTES
 

Numpy python cheat_sheet

  • 1. 2 PythonForDataScience Cheat Sheet NumPy Basics Learn Python for Data Science Interactively at www.DataCamp.com NumPy DataCamp Learn Python for Data Science Interactively The NumPy library is the core library for scientific computing in Python. It provides a high-performance multidimensional array object, and tools for working with these arrays. >>> import numpy as np Use the following import convention: Creating Arrays >>> np.zeros((3,4)) Create an array of zeros >>> np.ones((2,3,4),dtype=np.int16) Create an array of ones >>> d = np.arange(10,25,5) Create an array of evenly spaced values (step value) >>> np.linspace(0,2,9) Create an array of evenly spaced values (number of samples) >>> e = np.full((2,2),7) Create a constant array >>> f = np.eye(2) Create a 2X2 identity matrix >>> np.random.random((2,2)) Create an array with random values >>> np.empty((3,2)) Create an empty array Array Mathematics >>> g = a - b Subtraction array([[-0.5, 0. , 0. ], [-3. , -3. , -3. ]]) >>> np.subtract(a,b) Subtraction >>> b + a Addition array([[ 2.5, 4. , 6. ], [ 5. , 7. , 9. ]]) >>> np.add(b,a) Addition >>> a / b Division array([[ 0.66666667, 1. , 1. ], [ 0.25 , 0.4 , 0.5 ]]) >>> np.divide(a,b) Division >>> a * b Multiplication array([[ 1.5, 4. , 9. ], [ 4. , 10. , 18. ]]) >>> np.multiply(a,b) Multiplication >>> np.exp(b) Exponentiation >>> np.sqrt(b) Square root >>> np.sin(a) Print sines of an array >>> np.cos(b) Element-wise cosine >>> np.log(a) Element-wise natural logarithm >>> e.dot(f) Dot product array([[ 7., 7.], [ 7., 7.]]) Subsetting, Slicing, Indexing >>> a.sum() Array-wise sum >>> a.min() Array-wise minimum value >>> b.max(axis=0) Maximum value of an array row >>> b.cumsum(axis=1) Cumulative sum of the elements >>> a.mean() Mean >>> b.median() Median >>> a.corrcoef() Correlation coefficient >>> np.std(b) Standard deviation Comparison >>> a == b Element-wise comparison array([[False, True, True], [False, False, False]], dtype=bool) >>> a < 2 Element-wise comparison array([True, False, False], dtype=bool) >>> np.array_equal(a, b) Array-wise comparison 1 2 3 1D array 2D array 3D array 1.5 2 3 4 5 6 Array Manipulation NumPy Arrays axis 0 axis 1 axis 0 axis 1 axis 2 Arithmetic Operations Transposing Array >>> i = np.transpose(b) Permute array dimensions >>> i.T Permute array dimensions Changing Array Shape >>> b.ravel() Flatten the array >>> g.reshape(3,-2) Reshape, but don’t change data Adding/Removing Elements >>> h.resize((2,6)) Return a new array with shape (2,6) >>> np.append(h,g) Append items to an array >>> np.insert(a, 1, 5) Insert items in an array >>> np.delete(a,[1]) Delete items from an array Combining Arrays >>> np.concatenate((a,d),axis=0) Concatenate arrays array([ 1, 2, 3, 10, 15, 20]) >>> np.vstack((a,b)) Stack arrays vertically (row-wise) array([[ 1. , 2. , 3. ], [ 1.5, 2. , 3. ], [ 4. , 5. , 6. ]]) >>> np.r_[e,f] Stack arrays vertically (row-wise) >>> np.hstack((e,f)) Stack arrays horizontally (column-wise) array([[ 7., 7., 1., 0.], [ 7., 7., 0., 1.]]) >>> np.column_stack((a,d)) Create stacked column-wise arrays array([[ 1, 10], [ 2, 15], [ 3, 20]]) >>> np.c_[a,d] Create stacked column-wise arrays Splitting Arrays >>> np.hsplit(a,3) Split the array horizontally at the 3rd [array([1]),array([2]),array([3])] index >>> np.vsplit(c,2) Split the array vertically at the 2nd index [array([[[ 1.5, 2. , 1. ], [ 4. , 5. , 6. ]]]), array([[[ 3., 2., 3.], [ 4., 5., 6.]]])] Also see Lists Subsetting >>> a[2] Select the element at the 2nd index 3 >>> b[1,2] Select the element at row 1 column 2 6.0 (equivalent to b[1][2]) Slicing >>> a[0:2] Select items at index 0 and 1 array([1, 2]) >>> b[0:2,1] Select items at rows 0 and 1 in column 1 array([ 2., 5.]) >>> b[:1] Select all items at row 0 array([[1.5, 2., 3.]]) (equivalent to b[0:1, :]) >>> c[1,...] Same as [1,:,:] array([[[ 3., 2., 1.], [ 4., 5., 6.]]]) >>> a[ : :-1] Reversed array a array([3, 2, 1]) Boolean Indexing >>> a[a<2] Select elements from a less than 2 array([1]) Fancy Indexing >>> b[[1, 0, 1, 0],[0, 1, 2, 0]] Select elements (1,0),(0,1),(1,2)and (0,0) array([ 4. , 2. , 6. , 1.5]) >>> b[[1, 0, 1, 0]][:,[0,1,2,0]] Select a subset of the matrix’s rows array([[ 4. ,5. , 6. , 4. ], and columns [ 1.5, 2. , 3. , 1.5], [ 4. , 5. , 6. , 4. ], [ 1.5, 2. , 3. , 1.5]]) >>> a = np.array([1,2,3]) >>> b = np.array([(1.5,2,3), (4,5,6)], dtype = float) >>> c = np.array([[(1.5,2,3), (4,5,6)], [(3,2,1), (4,5,6)]], dtype = float) Initial Placeholders Aggregate Functions >>> np.loadtxt("myfile.txt") >>> np.genfromtxt("my_file.csv", delimiter=',') >>> np.savetxt("myarray.txt", a, delimiter=" ") I/O 1 2 3 1.5 2 3 4 5 6 Copying Arrays >>> h = a.view() Create a view of the array with the same data >>> np.copy(a) Create a copy of the array >>> h = a.copy() Create a deep copy of the array Saving & Loading Text Files Saving & Loading On Disk >>> np.save('my_array', a) >>> np.savez('array.npz', a, b) >>> np.load('my_array.npy') >>> a.shape Array dimensions >>> len(a) Length of array >>> b.ndim Number of array dimensions >>> e.size Number of array elements >>> b.dtype Data type of array elements >>> b.dtype.name Name of data type >>> b.astype(int) Convert an array to a different type Inspecting Your Array >>> np.info(np.ndarray.dtype) Asking For Help Sorting Arrays >>> a.sort() Sort an array >>> c.sort(axis=0) Sort the elements of an array's axis Data Types >>> np.int64 Signed 64-bit integer types >>> np.float32 Standard double-precision floating point >>> np.complex Complex numbers represented by 128 floats >>> np.bool Boolean type storing TRUE and FALSE values >>> np.object Python object type >>> np.string_ Fixed-length string type >>> np.unicode_ Fixed-length unicode type 1 2 3 1.5 2 3 4 5 6 1.5 2 3 4 5 6 1 2 3