Numpy module implemented using an array of shape change

table of Contents

1. Direct predetermined shape change directly through the shape tuples ----

2. Change --- reshape returns a new array

3. The high-latitude flattened array

(1) by Ravel () flattening

(2) Flatten () flattening


Create an array

import numpy as np
arr=np.arange(16)
print('arr:',arr)
print('arr形状:',arr.shape)
print(type(arr))

1. Direct predetermined shape change directly through the shape tuples ----

arr.shape(4,4)
print(arr)
print(arr.shape)

2. Change --- reshape returns a new array

arr_new=arr.reshape(4,4)
print(arr_new)
print(arr_new.shape)

3. The high-latitude flattened array

Create an array of high-latitude

import numpy as np
arr=np.arange(16).reshape(4,4)
print(arr)
print(arr.shape)

(1) by Ravel () flattening

arr_new=arr.ravel()
# arr_new=np.ravel(arr)
print(arr_new)

(2) Flatten () flattening

The default parameter is expanded by line C

F parameter is expanded by columns

arr_new=arr.flatten()
print('arr_new:',arr_new)
arr_new=arr.flatten('F')
print('arr_new:',arr_new)

 

Guess you like

Origin blog.csdn.net/g_optimistic/article/details/91951921