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)