0.0
No commit activity in last 3 years
No release in over 3 years
Arbitrary row/column selection for NMatrix
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

NMatrix row/col extension

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

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

Works with dense and sparse matrix types.

Install

gem install nmatrix-rowcol

Usage

require 'nmatrix/rowcol'

m = NMatrix.indgen [3,3]
# [ [0, 1, 2]   
#   [3, 4, 5]   
#   [6, 7, 8] ]

m.row [0,2]             
# [ [0, 1, 2]   
#   [6, 7, 8] ]

m.row m.sum(1) > 6      
# [ [3, 4, 5]   
#   [6, 7, 8] ]

m.col [0,2]             
# [ [0, 2]   
#   [3, 5]   
#   [6, 8] ]

m.col m.sum(0) > 12     
# [ [2]   
#   [5]   
#   [8] ]

m.row([0,2]).col([0,2])
# [ [0, 2]   
#   [6, 8] ]

m.col [2,0,1] # re-arrange columns
# [ [2, 0, 1]   
#   [5, 3, 4]   
#   [8, 6, 7] ]

m.row m.rows.times.to_a.sample(2) # random row samples
# [ [6, 7, 8]   
#   [0, 1, 2] ]

License

MIT