reshapeZ function
A collection of methods from various Python libraries (predominantly SciPy and NumPy) written in Dart These methods are mainly used for creating or manipulating matrices While Dart matrix libraries exist, they do not encompass the scope of well established Python libraries
Implementation
Matrix reshapeZ(var z, int dimZ, int nDim) {
assert(z is num || z is Vector || z is List<Vector> || z is Matrix,
'z must be num, Vector, List<Vector> or Matrix');
z = atLeast2D(z);
assert(z.rowsNum == 1 || z.columnsNum == 1,
'z must be a flat row or a flat column');
assert(z.rowsNum == dimZ || z.columnsNum == dimZ,
'dimZ must equal z rowsNum or z columnsNum');
if (z.columnsNum == dimZ) {
z = z.transpose();
}
if (nDim == 0) {
return Matrix.fromList([
[z.getRow(0).elementAt(0)]
]);
} else if (nDim == 1) {
return Matrix.fromColumns([z.getColumn(0)]);
}
return z;
}