changeDtype method

List changeDtype(
  1. List list,
  2. String? dtype
)

Implementation

List changeDtype(List list, String? dtype) {
  List shape = getDim(list);
  var flat;
  if (shape.length > 7) {
    throw new Exception(
        "DartTensorException : Only possible till 7 dimensions.");
  } else {
    flat = flatten(list);
    if (dtype == 'int') {
      flat = flat.map((e) => e.toInt()).toList();
    } else if (dtype == 'double') {
      flat = flat.map((e) => e.toDouble()).toList();
    } else if (dtype == 'string') {
      flat = flat.map((e) => e.toString()).toList();
    } else {
      throw new Exception(
          "DartTensorException : Wrong parameter input provided.");
    }
  }
  var temp = generate(flat, shape);
  return temp;
}