Numpy (numerical Python)
- Foundation package for high performance scientific computing and data analysis;
- Ndarray, multi-dimensional Array (matrix), with vector computing ability, fast, save space;
- Matrix operations, without loops, can be done similar to MATLAB in the vector operation;
- Linear algebra, random send generation;
Ndarray, n-dimensional array objects (matrices)
- All elements must be of the same type
- Ndim attribute, number of dimensions
- Shape attribute, size of each dimension
- Dtype property, data type
code example:
Import numpy# generate random multidimensional data for the specified dimension (two rows and three columns) data = Numpy.random.rand (2, 3) Print Dataprint type (data)
[[0.49458614 0.14245674 0.26883084] [0.87402248 0.71089966 0.29023523]]<type ' Numpy.ndarray ' >
print ' Number of dimensions ', Data.ndimprint ' Dimensions: ', Data.shapeprint ' data type: ', Data.dtype
Number of dimensions 2 dimension size: (2L, 3L) data type: float64
1. Create Ndarray
Nd.array (collection), collection is a Sequence object (list), nested sequence (list of lists)
# The list is converted to Ndarray (one-dimensional array) L = Range (Ten) data = Np.array (l) Print Dataprint Data.shapeprint Data.ndim
[0 1 2 3 4 5 6 7 8 9] (10L, 1)
# The nested sequence is converted to NDARRAYL2 = [Range], range (Ten)]data = Np.array (L2) Print Dataprint Data.shape
[[0 1 2 3 4 5 6 7 8 9] [0 1 2 3 4 5 6 7 8 9]] (2L, 10L)
Np.zeros,np.ones,np.empty full 0 or all 1 arrays of the specified size
- The first parameter is Ganso, which is used to specify the size, such as (3,4)
- Empty does not always return a total of 0, something returned is an uninitialized random value
Python data Analysis NumPy (ii)