Guest User

Untitled

a guest
May 1st, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. >>> class TestEllipsis(object):
  2. ... def __getitem__(self, item):
  3. ... if item is Ellipsis:
  4. ... return "Returning all items"
  5. ... else:
  6. ... return "return %r items" % item
  7. ...
  8. >>> x = TestEllipsis()
  9. >>> print x[2]
  10. return 2 items
  11. >>> print x[...]
  12. Returning all items
  13.  
  14. >>> from numpy import arange
  15. >>> a = arange(16).reshape(2,2,2,2)
  16.  
  17. >>> a[..., 0].flatten()
  18. array([ 0, 2, 4, 6, 8, 10, 12, 14])
  19.  
  20. >>> a[:,:,:,0].flatten()
  21. array([ 0, 2, 4, 6, 8, 10, 12, 14])
Add Comment
Please, Sign In to add comment