Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. import numpy as np
  2. A = np.random.rand(4,4)
  3. k = np.empty((4,4,4))
  4. for ix in range(4):
  5. for iy in range(4):
  6. x = A[ix,]
  7. y = A[iy,]
  8. sx = np.power(x - x[:,np.newaxis],2)
  9. sy = np.power(y - y[:,np.newaxis],2)
  10. k[ix,iy] = (sx + sy).sum().T
  11.  
  12. k[ix,iy] = (sx + sy).sum(axis=-1)
  13.  
  14. xij = (A[:, None, :] - A[..., None])**2
  15. k = np.sum(xij[:, None, :, :] + xij, axis=-1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement