UNPKG

mathjs

Version:

Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser and offers an integrated solution to work with numbers, big numbers, complex numbers, units, and matrices.

36 lines (31 loc) 800 B
module.exports = function (math) { var util = require('../../util/index'), Matrix = require('../../type/Matrix'), object = util.object, array = util.array, isArray = Array.isArray; /** * Remove singleton dimensions from a matrix * * squeeze(x) * * @param {Matrix | Array} x * @return {Matrix | Array} res */ math.squeeze = function squeeze (x) { if (arguments.length != 1) { throw new math.error.ArgumentsError('squeeze', arguments.length, 1); } if (isArray(x)) { return array.squeeze(object.clone(x)); } else if (x instanceof Matrix) { var res = array.squeeze(x.toArray()); return isArray(res) ? new Matrix(res) : res; } else { // scalar return object.clone(x); } }; };