当前位置:网站首页>Numpy——2. Shape of array

Numpy——2. Shape of array

2022-07-07 19:14:00 Hair will grow again without it

The shape of the array

View the shape of the array

a.shape()
You can judge how many dimensions the array is by the number of returned values
 Insert picture description here

Modify the shape of the array

a.reshape(x, y) Return value but not modified a Array
a.flatten() Turn the array directly into one dimension
 Insert picture description here > Insert picture description here

The calculation of array

Calculation of arrays and numbers

Broadcast mechanism
When calculating an array and a number , Apply this number to each element of the array , In fact, this number is expanded into the dimension of the sum array , Row number , An array with the same number of columns , Then do the operation on the corresponding element
 Insert picture description here

Arrays and the calculation of arrays

identical shape Array of The calculation of , Directly add, subtract, multiply and divide the corresponding elements
 Insert picture description here
Different shape Array of The calculation of , If it's two-dimensional , Rows and columns must have the same dimension , The other dimension is 1. If it is 3 One dimension minus one two dimension , Also look at rows and columns
It is also a broadcasting mechanism , It will expand the small one dimension of the row or column to the large one

 Insert picture description here
example A two-dimensional
 Insert picture description here
example The three dimensional
 Insert picture description here
 Insert picture description here

原网站

版权声明
本文为[Hair will grow again without it]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071703239078.html