squeeze method
Remove a dimension of size 1 at the given position.
Implementation
Tensor squeeze([int? dim]) {
if (dim != null) {
assert(shape[dim] == 1, 'Can only squeeze dim of size 1');
final newShape = List<int>.from(shape);
newShape.removeAt(dim);
if (newShape.isEmpty) newShape.add(1);
return reshape(newShape);
}
final newShape = shape.where((s) => s != 1).toList();
if (newShape.isEmpty) newShape.add(1);
return reshape(newShape);
}