![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
np
some function of np
zz不倦
从事模式识别,通信对抗与干扰。
展开
-
np.where() -- Numpy
添加链接描述转载 2021-12-14 11:41:51 · 66 阅读 · 0 评论 -
Broadcast 机制——numpy
几种情况:1.末维不等时, 报错。a = np.arange(12).reshape(4, 1, 3) b = np.arange(6).reshape(3, 2)print(a, "\n", b, "\n", a+b)ValueError: operands could not be broadcast together with shapes (4,1,3) (3,2) 2.末维等。维数不等时,当有某一维维度数不等时报错。2 =!3a = np.arange(24).reshape(4原创 2021-11-29 17:47:44 · 977 阅读 · 0 评论 -
计算两点间连线的倾斜角--python
计算两点间连线的倾斜角.这种方法非常的有用.Math.atan2()函数返回点(x,y)和原点(0,0)之间直线的倾斜角.那么如何计算任意两点间直线的倾斜角呢?只需要将两点x,y坐标分别相减得到一个新的点(x2-x1,y2-y1).然后利用他求出角度就可以了.使用下面的一个转换可以实现计算出两点间连线的夹角.Math.atan2(y2-y1,x2-x1)不过这样我们得到的是一个弧度值,在一般情况下我们需要把它转换为一个角度.下面我们用一段代码来测试一下这样的转换.//测试,计算点(3,3)和(5翻译 2021-11-29 10:40:26 · 4089 阅读 · 0 评论 -
Numpy中排序操作partition,argpartition,sort,argsort
很好的说明:转载 2021-11-25 17:26:27 · 60 阅读 · 0 评论 -
np.where和*np.where---numpy
b = np.random.randint(0, 10, (4, 3)) print(b)"""[[5 2 2] [1 3 0] [8 9 0] [1 4 8]]"""print(np.where(b>5))## (array([2, 2, 3], dtype=int64), array([0, 1, 2], dtype=int64))print(*np.where(b>5))## [2 2 3] [0 1 2]原创 2021-11-22 09:29:49 · 1193 阅读 · 0 评论 -
list,array, asarray, ndarray
import numpy as npdata0 = [[1,1,1],[1,1,1],[1,1,1]] # dtype = 'list'data1 = np.array([[1.,1.,1.],[1.,1.,1.],[1.,1.,1.]])data1_1 = np.array(data0)data2 = np.asarray(data0)print(data2, data2.dtype)print(data2 is data1_1)data3 = np.ones((3, 3)) # 默认生原创 2021-09-29 21:13:40 · 99 阅读 · 0 评论 -
代数与概率##范数
##范数, linalg.norm() \\x\\p=(usm(x^p))^(1/p):p范数import numpy as npimport numpy.linalg as LA #Numpy中的线性代数库x = np.arange(0, 1, 0.1)x1 = LA.norm(x, 1)x2 = LA.norm(x, 2)xa = LA.norm(x, np.inf)print(x)print(x1, x2, xa)##特征值分解 lina原创 2021-05-31 22:19:09 · 104 阅读 · 0 评论 -
矩阵Matrix
#矩阵Matrix (np.linalg函数)import numpy as np nd14 = np.arange(9).reshape([3, 3])print(np.transpose(nd14))#转置a = np.arange(12).reshape([3, 4])b = np.arange(8).reshape([4, 2])print('============')print(a)print('============')print(b)print('==========原创 2021-05-31 22:12:39 · 133 阅读 · 0 评论 -
#存取元素
#存取元素import numpy as npnp.random.seed(2018)nd11 = np.random.random([10])print(nd11)print('============')print(nd11[3]) #取第4个数print('============')print(nd11[3:7]) #取一段4-7print('============')print(nd11[1:6:2])#间隔取数print('============')print(n原创 2021-05-31 22:11:32 · 105 阅读 · 0 评论 -
To create the ndarray
#NunmPy ndarray and ufunc#some ways to create the ndarray (N-dimension array object)import numpy as nplist1 = [3.14, 2.17, 0, 1.2] #列表nd1 = np.array(list1)print(nd1)print(type(nd1))print('================')#lists form to demensions ndarraylist2 =原创 2021-05-31 22:10:20 · 61 阅读 · 0 评论 -
合并np.c_[]. np.r_[] np.append() np.concatenate()展平np.ravel()
#np.ravel() #np.c_[]. np.r_[]import numpy as npa = np.array([1, 2, 4])f = np.array([3, 2, 6])c_con = np.c_[a, f] #列堆叠(列相加),行相等。np.c_[3*1, 3*1]=3*2r_con = np.r_[a, f] #行堆叠(行相加),列相等。np.r_[3*1, 3*1]=6*1print(c_con)print(r_con)print("===============原创 2021-05-06 19:07:27 · 227 阅读 · 0 评论 -
np中的0,1轴。方括号。np.sum函数
#np中的0,1轴。方括号。np.sum函数。import numpy as npa = np.array([1, 2, 4]) #此为(3,)阵,为列阵?b = np.array([[5, 3, 6]]) #此为(1, 3)阵,为行阵 print(a.shape, b.shape)print("===================")c = np.array([[1, 2, 6],[2, 2, 4],[5, 2, 1],[1, 4, 2]])print(c)print(c.shape原创 2021-05-06 17:36:00 · 184 阅读 · 0 评论