||
##import matplotlib.pyplot as plt
##import numpy as np
##
### 坐标轴位置变化
##
##plt.xlim(-5,5)
##plt.ylim(-4,4)
##
##
###
##ax = plt.gca()
##ax.spines["right"].set_color("none")
##ax.spines["top"].set_color("none")
##ax.xaxis.set_ticks_position("bottom")
##ax.yaxis.set_ticks_position("left")
##ax.spines["bottom"].set_position(("data",1))
##ax.spines["left"].set_position(("data",1))
###plt.show(block="False")
##
##
###numpy
##
##
##a= np.array([2,3,4],dtype=np.int32)
##print(a.dtype)
##
##a = np.zeros((3,4))
##b = np.ones((3,4))
##c = np.empty((4,5))
##d = np.arange(10,21,2)
##
##d2= np.linspace(0,12,12)
##e = d2.reshape((3,4))
##
##
##print(e)
##
##
###numpy array
##
##
##a = np.array([[1,1],
## [0,1]])
##b = np.arange(4).reshape((2,2))
##
##c=a*5 #各对应元素相乘
##c_dot_1 = np.dot(a,b) #矩阵相乘方法1
##c_dot_2 = a.dot(b) #矩阵相乘方法2
##
##A= np.arange(2,14).reshape(3,4)
##aa = np.cumsum(A)#累加
##bb = np.diff(A)
##
##print(aa)
##print(bb)
##print(np.nonzero(A))
##
##A = np.arange(14,2,-1).reshape(3,4)
##b = np.clip(A,5,9)#数组中所有大于9的数都变成9,所有小于5的数都变成5
##print(b)
##
##print(A.flatten()) #变成只有一行
##for item in A.flat:
## print(item)
##
##
###numpy 矩阵合并
##A = np.array([1,1,1])
##B = np.array([2,2,2])
##C = np.vstack((A,B)) #vertical stack
##D = np.hstack((A,B)) #horizontal stack
##print(D)
##
##E = A[np.newaxis,:]#在现有维度加了一个维度
##print(E.shape)
##C = np.concatenate((A,B,B,A),axis=0)#指定在哪一个维度合并
##
##
###numpy 矩阵分割
##A = np.arange(12).reshape(3,4)
##B = np.split(A,2,axis=1)
##C = np.array_split(A,3,axis=1) #不等分割
##
##E = np.vsplit(A,3) #纵向分割
##F = np.hsplit(A,2)
##
###深拷贝
##a = [1,2,3,4]
##b = a.copy() #deep copy
##
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-5-17 15:06
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社