numpy 矩阵的运算

N.arange(0,3)  : effect:array([0, 1, 2])

x = [[1,2,3,4],[2,3,4,5],[3,4,5,6]]

 

N.column_stack((N.arange(0,m),x)) effect :

array([[0, 1, 2, 3, 4],
[1, 2, 3, 4, 5],
[2, 3, 4, 5, 6]])

 

matrix operation:

复制代码
 def euclid(i, x):
  9     """euclidean(i, x) -> euclidean distance between x and y"""
 10     y = np.zeros_like(x)
 11     y += 1    // all elements add 1
 12     y *= i    // matrix product
 13     if len(x) != len(y):
 14         raise ValueError, "vectors must be same length"
 15 
 16     d = (x-y)**2
 17     return np.sqrt(np.sum(d, axis = 1))
复制代码

i:is 1-D array, x:is 2-D array

axis = 0 operation on row;  1 : operation on column;

条件 操作:

 i1 = numpy.where(D2<=Eps)

 

posted on   Harveyaot  阅读(341)  评论(0编辑  收藏  举报

努力加载评论中...

导航

< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8
点击右上角即可分享
微信分享提示