Module: MachineLearningWorkbench::Monkey::Mappable

Defined in:
lib/machine_learning_workbench/monkey.rb

Instance Method Summary collapse

Instance Method Details

#map(dim = 0) ⇒ NArray

Maps along a NArray dimension, and returns NArray NOTE: this indexing is not consistent with NArray, which uses 0 to indicate

columns rather than the 0th dimension (rows)

Returns:

Raises:

  • (ArgumentError)


301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/machine_learning_workbench/monkey.rb', line 301

def map dim=0
  raise ArgumentError unless dim.kind_of?(Integer) && dim.between?(0,ndim)
  # TODO: return iterator instead of raise
  raise NotImplementedError unless block_given?
  indices = [true]*ndim
  ret = []
  shape[dim].times.each do |i|
    indices[dim] = i
    ret << yield(self[*indices])
  end
  self.class[*ret]
end