Advertisement
Guest User

test in-place take

a guest
Jan 23rd, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. import numpy as np
  2. print np.version.version
  3.  
  4. N = 10
  5.  
  6. # gen ref matrix and permutation
  7. ref = np.arange(N*N)
  8. ref.resize(N,N)
  9. rr = range(N)
  10. np.random.shuffle(rr)
  11.  
  12. arr = ref.copy()
  13. res = (arr.take(rr,axis=0) == ref[rr,:]).all()
  14. print "test take, not overwriting:", res
  15.  
  16. arr = ref.copy()
  17. arr.take(rr,axis=0,out=arr,mode="raise")
  18. print "test not-in-place take:", (arr == ref[rr,:]).all()
  19.  
  20. arr = ref.copy()
  21. arr.take(rr,axis=0,out=arr,mode="clip")
  22. res = (arr == ref[rr,:]).all()
  23. print "test in-place take:", res
  24. if not res:
  25.     print "rr", rr
  26.     print "arr", arr[:,0]
  27.     print "ref", ref[rr,0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement