程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python basic skills numpy2

編輯:Python

Indexes

There are two forms of indexing , The first is similar to c In language , One ‘【】’ Put a number in , Each represents the line , Column , For one dimension, it is the access of array , The first few .

The second is python Unique to ,【 That's ok , Column 】 perhaps 【:, Column 】or【 That's ok ,:】 That is, all the numbers in a column or all the numbers in a row . It can also be used a:b Such from a To b In combination with .

a=np.arange(3,15).
// Normal version
print(a[n]) //c Index of language versions
// Upgraded version , It is mainly reflected in two dimensions
b=a.reshape(3,4)
print(b[2,1])
print(b[:,1]) or print(1,:)
print(1:2,1) Represents the second number to the third number in the second column 

  Combination of matrices

A=np.array([1,1,1])
B=np.array([2,2,2])
np.vstack((A,B)) //vertical stack Up and down adhesion Namely [[1,1,1],
[2,2,2]]
np.hstack((A,B))// Horizontal merger [1,1,1,2,2,2]
// A combination of multiple one-dimensional arrays
np.concatenate(array1,array2.... ,axis) //axis by 0 For vertical merger , by 1 For horizontal merger

Dimensional transformation of matrix

A=np.array([1,1,1])
// When I want to output vertically A When , I need him to change dimensions
B=A[:,np.newaxis] Represents adding a dimension to a column , Can achieve the output vertical 1,1,1 The effect of
B=A[np.newaxis.:] Represents adding a dimension to a row ,1,1,1 As a row of a two-dimensional array 

 

Partition of matrix  

// Need to use split(araray,sectors,axis) From that matrix Along that axis Split into pieces
A=np.arange(12).reshape((3,4))
print(np.split(A,2,axis=1))
// because split It can only be distributed equally , For example, divide the four columns into 1 Column , Two , Or four columns , But it can't be divided into three columns , So there is array_split
To achieve this goal , And the parameters and split equally
print(np.array_split(A,3,axis=1))
// There are also two functions that can achieve vertical segmentation and horizontal segmentation
print(np.hsplit(A,3))
print(np.vsplit(A,4))

Matrix assignment  

 

// Simple deep and shallow copies
a=np.arange(4)
b=a
c=a
This is a shallow copy , change a Value b The value of
d=a.copy()
This is a deep copy , change a Value ,d The value of 


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved