INNER CODE UNIT · Ruby
convert_to_matrix
yoshoku/rumale · rumale-core/lib/rumale/dataset.rb:196
def convert_to_matrix(data, n_features, dtype)
mat = []
data.each do |ft|
vec = Array.new(n_features) { 0 }
ft.each { |el| vec[el[0]] = el[1] }
mat.push(vec)
end
dtype.asarray(mat)
end
def detect_dtype(data)
arr_type_str = Numo::NArray.array_type(data).to_s
type = '%s'
type = '%d' if ['Numo::Int8', 'Numo::Int16', 'Numo::Int32', 'Numo::Int64'].include?(arr_type_str)
type = '%d' if ['Numo::UInt8', 'Numo::UInt16', 'Numo::UInt32', 'Numo::UInt64'].include?(arr_type_str)
type = '%.10g' if ['Numo::SFloat', 'Numo::DFloat'].include?(arr_type_str)
type
end