Method: NMatrix#reshape
- Defined in:
- lib/nmatrix/nmatrix.rb
#reshape(new_shape, *shapes) ⇒ Object
call-seq:
reshape(new_shape) -> NMatrix
Clone a matrix, changing the shape in the process. Note that this function does not do a resize; the product of the new and old shapes’ components must be equal.
-
Arguments :
-
new_shape-> Array of positive Fixnums.
-
-
Returns :
-
A copy with a different shape.
-
550 551 552 553 554 555 556 557 558 559 560 561 |
# File 'lib/nmatrix/nmatrix.rb', line 550 def reshape new_shape,*shapes if new_shape.is_a?Fixnum newer_shape = [new_shape]+shapes else # new_shape is an Array newer_shape = new_shape end t = reshape_clone_structure(newer_shape) left_params = [:*]*newer_shape.size right_params = [:*]*self.shape.size t[*left_params] = self[*right_params] t end |