注:因为Numpy的官方文档是全英文的,本篇文章也基本使用英文写作,部分知识、注释有中文。
1. Quickstart Tutorial
1.1 Prerequisites
1.2 The Basics
-
ndarray.ndim
The number of the axis(dimensions) of the array
-
ndarray.shape
The dimension of a array. If a matrix with nrows and mcolumns, the shape will be (n,m)
-
ndarray.size
The total number of elements of the array. This is equal to the product of the elements of shape
.
-
ndarray.dtype
An object describing the type of the elements in the array.
-
ndarray.itemsize
The size in bytes of each element of the array. For example, an array of elements of type float64 has itemsize 8 (=64/8), while one of type complex32 has itemsize 4 (=32/8).
-
ndarray.data
The buffer containing actual elements of the array.
-
# Example
>>> import numpy as np
>>> a = np.arange(15).reshape(3,5)
>>> a
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14]])
>>> a.shape
(3, 5)
>>> a.itemsize
8
>>> a.dtype
dtype('int64')
>>> a.dtype.name
'int64'
>>> a.size
15
>>> a.ndim
2
>>> type(a)
<class 'numpy.ndarray'>
1.3 Array Creation
1)Create an array from a regular Python list or tuple using the array function
-
Example
>