Array Fundamentals

Indexing

  1. import numpy as np
  2. one = np.array([10, 20, 30, 40, 50, 60, 70, 80])
  3. # basic indexing
  4. one[2]
  5. # slicing
  6. one[1:6:2]
  7. # fancy indexing
  8. one[[4,0,3,0]]
  9. # masking
  10. one[(one < 30) & (one > 60)]
  11. # newaxis / none-indexing
  12. one[:, np.newaxis]
  13. one[:, None]
  14. # higher dimensional array
  15. two = np.arange(27).reshape(3,3,3)
  16. # ellipsis indexing
  17. two[1, ...]

Google tag (gtag.js)