lib/tensor_stream/tensor.rb
# Base class that defines a tensor like interface
Base class that defines a tensor like interface
Base class that defines a tensor like interface
def reshape(arr, shape)
      if arr.is_a?(Array)
        return arr if shape.size < 2
        slice = shape.shift
        arr.each_slice(slice).collect do |s|
          reshape(s, shape)
        end
      else
        return arr if shape.empty?
        slice = shape.shift
        return arr if slice.nil?
        Array.new(slice) do
          reshape(arr, shape.dup)
        end
      end
    end
def reshape ( arr , shape ) if arr . is_a? ( Array ) return arr if shape . size < 2 slice = shape . shift arr . each_slice ( slice ) . collect do | s | reshape ( s , shape ) end else return arr if shape . empty? slice = shape . shift return arr if slice . nil? Array . new ( slice ) do reshape ( arr , shape . dup ) end end end
Base class that defines a tensor like interface
Base class that defines a tensor like interface
arr
<not_specific>
shape
<not_specific>