项目作者: gbuesing

项目描述 :
Arbitrary row/column selection for NMatrix
高级语言: Ruby
项目地址: git://github.com/gbuesing/nmatrix-rowcol.git
创建时间: 2015-08-30T03:34:20Z
项目社区:https://github.com/gbuesing/nmatrix-rowcol

开源协议:

下载


NMatrix row/col extension

Arbitrary row/column selection for NMatrix. Allows you to do selections like:

  1. x.col([0,2]).row(y =~ 'setosa')

Works with dense and sparse matrix types.

Install

  1. gem install nmatrix-rowcol

Usage

  1. require 'nmatrix/rowcol'
  2. m = NMatrix.indgen [3,3]
  3. # [ [0, 1, 2]
  4. # [3, 4, 5]
  5. # [6, 7, 8] ]
  6. m.row [0,2]
  7. # [ [0, 1, 2]
  8. # [6, 7, 8] ]
  9. m.row m.sum(1) > 6
  10. # [ [3, 4, 5]
  11. # [6, 7, 8] ]
  12. m.col [0,2]
  13. # [ [0, 2]
  14. # [3, 5]
  15. # [6, 8] ]
  16. m.col m.sum(0) > 12
  17. # [ [2]
  18. # [5]
  19. # [8] ]
  20. m.row([0,2]).col([0,2])
  21. # [ [0, 2]
  22. # [6, 8] ]
  23. m.col [2,0,1] # re-arrange columns
  24. # [ [2, 0, 1]
  25. # [5, 3, 4]
  26. # [8, 6, 7] ]
  27. m.row m.rows.times.to_a.sample(2) # random row samples
  28. # [ [6, 7, 8]
  29. # [0, 1, 2] ]

License

MIT