{"_id":"@0xcmdr/numjs","_rev":"2-845a9efd8720821590165335bebe5b73","name":"@0xcmdr/numjs","dist-tags":{"latest":"0.16.1"},"versions":{"0.16.0":{"name":"@0xcmdr/numjs","version":"0.16.0","description":"Like NumPy, in JavaScript","main":"src/index.js","directories":{"test":"test"},"dependencies":{"cwise":"^1.0.10","deasync":"^0.1.20","lodash":"^4.17.15","ndarray":"^1.0.19","ndarray-fft":"^1.0.3","ndarray-gemm":"^1.0.0","ndarray-ops":"^1.2.2","sharp":"^0.25.2","typedarray-pool":"^1.2.0"},"devDependencies":{"browserify-shim":"^3.8.14","chai":"^4.2.0","expect.js":"^0.3.1","grunt":"^1.1.0","grunt-browserify":"^5.3.0","grunt-contrib-uglify":"latest","grunt-gh-pages":"^4.0.0","grunt-jsdoc":"^2.4.1","grunt-karma":"^4.0.0","grunt-semistandard":"^1.0.6","grunt-simple-mocha":"^0.4.1","ink-docstrap":"^1.3.2","jasmine":"^3.5.0","jasmine-core":"^3.5.0","jit-grunt":"^0.10.0","karma":"^5.0.2","karma-browserify":"^7.0.0","karma-chai":"^0.1.0","karma-jasmine":"^3.1.1","karma-mocha":"^2.0.0","karma-mocha-reporter":"latest","karma-phantomjs-launcher":"^1.0.4","mocha":"^7.1.2","phantomjs-prebuilt":"^2.1.16","semistandard":"^14.2.0"},"semistandard":{"globals":["HTMLImageElement","HTMLCanvasElement","nj","Image"]},"scripts":{"test":"grunt test","preversion":"grunt test && git ci dist -m 'bump version' --allow-empty ","postversion":"npm publish && grunt doc"},"repository":{"type":"git","url":"git+https://github.com/0xcmdr/numjs-Node13.git"},"keywords":["ndarray","array","multi","multidimensional","dimension","higher","image","volume","webgl","tensor","matrix","linear","algebra","science","numerical","computing","stride","shape","numpy"],"author":{"name":"Nicolas Panel"},"license":"MIT","browser":{"./src/images/resize.js":"./src/images/resize-dom.js","./src/images/read.js":"./src/images/read-dom.js","./src/images/save.js":"./src/images/save-dom.js","buffer":"./src/buffer-dom.js"},"browserify-shim":{},"browserify":{"transform":["cwise","browserify-shim"]},"standard":{"globals":["HTMLImageElement","HTMLCanvasElement","nj","Image"]},"gitHead":"8bc3d8b5159a4a5aa69800de88fabe3fe35cc6b7","bugs":{"url":"https://github.com/0xcmdr/numjs-Node13/issues"},"homepage":"https://github.com/0xcmdr/numjs-Node13#readme","_id":"@0xcmdr/numjs@0.16.0","_nodeVersion":"13.13.0","_npmVersion":"6.14.4","dist":{"integrity":"sha512-VgRsNbIRe5vCnfo597k9GDRIeuhvhK0qsIelPrGhNmFH5o/aygk6oa3fVa8FwAmIJ0gIAFQT6ohZ2L7ahqUIpw==","shasum":"8bc51f70710761f6567b2ff15ab60d7ca8394f83","tarball":"https://registry.npmjs.org/@0xcmdr/numjs/-/numjs-0.16.0.tgz","fileCount":35,"unpackedSize":719695,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeqFU2CRA9TVsSAnZWagAAz6YP/RpS/0TbGMrWcgaEqgd6\nEfLwcm94rL7NgjvXl7ymcQdgq9PSfweYrQAGuRy0YMRzGUOvEx1PxSfAAWbs\nm1VhCnfpMk8AGHNx3wBb9Cc4VPfvP0FnrIqju7tQLvDW2mKOXk8WT32aP8N5\n72hnpNPUebIp0PMhRCAce3lvekswt22XaSRUsc4JXkLFgGCGDmyqplRMwpcA\nwosu71bgq0b8zuhIZgaB/KwPwnKFU0BfNET5fTJZfX2Ih147reBnb3a8GH6/\n9jEeQ3mCcbp4xsdLVTHqrcQi/f4qN1B+b+LI4Jt5Ztit+/7E42LXb8lhqMGa\nBAyXDFs8w+oX/owNDzbK6jrUPDfguxLawqmcXYiLfrd+qBKbZIoiTcb1xNTF\n7b43PizaTW8ZA4lMZ7UocJYF3LhlHCQ3h3gTGkHR6lDbVCHxynzRhlRC9qZi\n82d3rBadO5fQupkmMTzbyf1mtJJWfkIywW7GZAt7cLfdTyHTUcFW3QgMUabg\nMyTyoMwVNQVcAC6tWJ8uDg5m0tjbW/cUFtESj/thyK9+k60B0hAxwXnWUTVk\nVqs5uCgVlszBvyGCTiZaXU2FzXpQrnkguVuQFc4xxUVQmA6WFegr24iIXF6I\nCq4QDdAVQQ8qV0mOgQwTwoJSCVhCZP5t8O4R4BFVGSBJpHyG4i8bXs0xVnnp\n7AlF\r\n=s8tG\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDwO8f6ipCi5SVerZWqjV6Rddzoq+07AmhzjYMNfhG/swIgDCyVoO3Cd1MrWt9VuqbLoVlUUdkovm7pQbSQZAZjtEU="}]},"maintainers":[{"name":"0xcmdr","email":"contact@cmduran.com"}],"_npmUser":{"name":"0xcmdr","email":"contact@cmduran.com"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/numjs_0.16.0_1588090165457_0.7688314811992403"},"_hasShrinkwrap":false},"0.16.1":{"name":"@0xcmdr/numjs","version":"0.16.1","description":"Like NumPy, in JavaScript (updated and fixed for NodeJS v13)","main":"src/index.js","directories":{"test":"test"},"dependencies":{"cwise":"^1.0.10","deasync":"^0.1.20","lodash":"^4.17.15","ndarray":"^1.0.19","ndarray-fft":"^1.0.3","ndarray-gemm":"^1.0.0","ndarray-ops":"^1.2.2","sharp":"^0.25.2","typedarray-pool":"^1.2.0"},"devDependencies":{"browserify-shim":"^3.8.14","chai":"^4.2.0","expect.js":"^0.3.1","grunt":"^1.1.0","grunt-browserify":"^5.3.0","grunt-contrib-uglify":"latest","grunt-gh-pages":"^4.0.0","grunt-jsdoc":"^2.4.1","grunt-karma":"^4.0.0","grunt-semistandard":"^1.0.6","grunt-simple-mocha":"^0.4.1","ink-docstrap":"^1.3.2","jasmine":"^3.5.0","jasmine-core":"^3.5.0","jit-grunt":"^0.10.0","karma":"^5.0.2","karma-browserify":"^7.0.0","karma-chai":"^0.1.0","karma-jasmine":"^3.1.1","karma-mocha":"^2.0.0","karma-mocha-reporter":"latest","karma-phantomjs-launcher":"^1.0.4","mocha":"^7.1.2","phantomjs-prebuilt":"^2.1.16","semistandard":"^14.2.0"},"semistandard":{"globals":["HTMLImageElement","HTMLCanvasElement","nj","Image"]},"scripts":{"test":"grunt test","preversion":"grunt test && git ci dist -m 'bump version' --allow-empty ","postversion":"npm publish && grunt doc"},"repository":{"type":"git","url":"git://github.com/nicolaspanel/numjs.git"},"keywords":["ndarray","array","multi","multidimensional","dimension","higher","image","volume","webgl","tensor","matrix","linear","algebra","science","numerical","computing","stride","shape","numpy"],"author":{"name":"Nicolas Panel"},"license":"MIT","browser":{"./src/images/resize.js":"./src/images/resize-dom.js","./src/images/read.js":"./src/images/read-dom.js","./src/images/save.js":"./src/images/save-dom.js","buffer":"./src/buffer-dom.js"},"browserify-shim":{},"browserify":{"transform":["cwise","browserify-shim"]},"standard":{"globals":["HTMLImageElement","HTMLCanvasElement","nj","Image"]},"gitHead":"8bc3d8b5159a4a5aa69800de88fabe3fe35cc6b7","bugs":{"url":"https://github.com/nicolaspanel/numjs/issues"},"homepage":"https://github.com/nicolaspanel/numjs#readme","_id":"@0xcmdr/numjs@0.16.1","_nodeVersion":"13.13.0","_npmVersion":"6.14.4","dist":{"integrity":"sha512-m59o8rJ2jZk0f1d3pXHrv9OAURIq1bb8woBXZn9IKhiSubSw9VXYJj9IMA0F2/YYmEuyjqhH8o7urWS1sWkDRQ==","shasum":"4a4a479f4007165f1290f80e4ad1dd6025f20e9f","tarball":"https://registry.npmjs.org/@0xcmdr/numjs/-/numjs-0.16.1.tgz","fileCount":35,"unpackedSize":719748,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeqGFvCRA9TVsSAnZWagAAvJkQAKFVg+o7sJ/OYZlsaEAx\nLw7+U80R139HvUXlJgO6QVjfZlgrm/G3eGKm4o3lGGZR19+v3Mn7UjCuAj/0\nchUmyTbCuBN9nK7I8KPL4ZuEKkc9o8Rmv2zZUBlGXaAVRT96GoCRpU/Icodu\nC9kvb7HEufb9IZ1DBDsJLaqi9dzVj+WjCh5KNL/of7h/aBH1Q5otLIlnUOuX\n9MK7gYkUTCAtadoJYLTSOdK/G6rNDz5LcT/4TtX/e7O8iLFffnZT8TvpZtgV\nv1qdrCGNL0iNQMLHKEnL/NXh0X4hlh0E2X7q3YckpKZtEWOA6VRCKprmTmG7\naOcFba6hafKGErvEnJuTGMvFDJMopGgNG7gIb61K9SExlcXyy5svAuqcDyip\nEv8N4YyXwgDnUtMSeBVE8kD6W9t+7sLy8SW5VpvR6RZ2373bzb7P4dn8QWCZ\nN/12fwkaK+9yl54DKxdHhDuAdke6VNSRyWowQ4dX10C75XdzVjfBAQfw1ia2\nXc39VscwwzAeOwTXLw2FzL2OUCsIznkbkaGgDLM1UC7T6rOonYOKPRFwLeUi\nCdOuzwr6hsqmztpi+b7OvBiPu6COLnznl9YkwrEOGt0ZfUv5T/bDtMFpQRM+\nRCllAQhQl1C/ECzvPV62KdfpZ46BKARyWRN4FRBTYms6FgJXIRzWUDtFYbYL\nOmyX\r\n=VweD\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDW1SkwfWLYTPQMp5HszLJnFoumh4z35muOc1Aqn8xYdAIhAN4tRROsOnpnRvxTcE8wRYQHKCCwVlAB2Skfu5iBG9/w"}]},"maintainers":[{"name":"0xcmdr","email":"contact@cmduran.com"}],"_npmUser":{"name":"0xcmdr","email":"contact@cmduran.com"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/numjs_0.16.1_1588093295137_0.755838332368562"},"_hasShrinkwrap":false}},"time":{"created":"2020-04-28T16:09:25.415Z","0.16.0":"2020-04-28T16:09:25.616Z","modified":"2022-04-04T10:28:54.175Z","0.16.1":"2020-04-28T17:01:35.359Z"},"maintainers":[{"name":"0xcmdr","email":"contact@cmduran.com"}],"description":"Like NumPy, in JavaScript (updated and fixed for NodeJS v13)","homepage":"https://github.com/nicolaspanel/numjs#readme","keywords":["ndarray","array","multi","multidimensional","dimension","higher","image","volume","webgl","tensor","matrix","linear","algebra","science","numerical","computing","stride","shape","numpy"],"repository":{"type":"git","url":"git://github.com/nicolaspanel/numjs.git"},"author":{"name":"Nicolas Panel"},"bugs":{"url":"https://github.com/nicolaspanel/numjs/issues"},"license":"MIT","readme":"[![Build Status](https://travis-ci.org/nicolaspanel/numjs.png)](https://travis-ci.org/nicolaspanel/numjs) [![npm version](https://badge.fury.io/js/numjs.svg)](https://badge.fury.io/js/numjs) [![Bower version](https://badge.fury.io/bo/numjs.svg)](https://badge.fury.io/bo/numjs) [![Built with Grunt](https://cdn.gruntjs.com/builtwith.svg)](http://gruntjs.com/)\n\n__NumJs__ is a npm/bower package for scientific computing with JavaScript. It contains among other things:\n - a powerful N-dimensional array object\n - linear algebra function\n - fast Fourier transform\n - tools for basic image processing\n\nBesides its obvious scientific uses, __NumJs__ can also be used as an efficient multi-dimensional container of generic data.\n\nIt works both in node.js and in the browser (with or without [browserify](http://browserify.org/))\n\n__NumJs__ is licensed under the [MIT license](https://github.com/nicolaspanel/numjs/blob/master/LICENSE), enabling reuse with almost no restrictions.\n\n__[See this jsfiddle](https://jsfiddle.net/nicolaspanel/047gwg0q/)__ for a concrete example of how to use the library to manipulate images in the browser.\n\n## Installation (updated and fixed for NodeJS v13)\n\n### prerequsities\n\n```sh\nnpm install -g node-gyp\n```\n### install package\n```sh\nnpm install @0xcmdr/numjs\n\nor\n\nyarn add @0xcmdr/numjs\n```\n\n```js\nvar nj = require('numjs');\n...\n```\n\n### on the browser (NOT UPDATED)\n```sh\nbower install numjs\n```\n\n```html\n<script src=\"bower_packages/numjs/dist/numjs.min.js\"></script>\n<!-- or include it directly from a CDN -->\n<script src=\"https://cdn.jsdelivr.net/gh/nicolaspanel/numjs@0.15.1/dist/numjs.min.js\"></script>\n```\n\n## Basics\n\n### Array Creation\n\n```js\n> var a = nj.array([2,3,4]);\n> a\narray([ 2, 3, 4])\n> var b = nj.array([[1,2,3], [4,5,6]]);\n> b\narray([[ 1, 2, 3],\n       [ 4, 5, 6]])\n```\n\n__Note__: Default data container is Javascript `Array` object. If needed, you can also use typed array such as `Uint8Array`:\n\n```js\n> var a = nj.uint8([1,2,3]);\n> a\narray([ 1, 2, 3], dtype=uint8)\n```\n\n__Note__: possible types are int8, uint8, int16, uint16, int32, uint32, float32, float64 and array (the default)\n\nTo create arrays with a given shape, you can use `zeros`, `ones` or `random` functions:\n\n```js\n> nj.zeros([2,3]);\narray([[ 0, 0, 0],\n       [ 0, 0, 0]])\n> nj.ones([2,3,4], 'int32')     // dtype can also be specified\narray([[[ 1, 1, 1, 1],\n        [ 1, 1, 1, 1],\n        [ 1, 1, 1, 1]],\n       [[ 1, 1, 1, 1],\n        [ 1, 1, 1, 1],\n        [ 1, 1, 1, 1]]], dtype=int32)\n\n> nj.random([4,3])\narray([[ 0.9182 , 0.85176, 0.22587],\n       [ 0.50088, 0.74376, 0.84024],\n       [ 0.74045, 0.23345, 0.20289],\n       [ 0.00612, 0.37732, 0.06932]])\n```\n\nTo create sequences of numbers, __NumJs__ provides a function called `arange`:\n\n```js\n> nj.arange(4);\narray([ 0, 1, 2, 3])\n\n> nj.arange( 10, 30, 5 )\narray([ 10, 15, 20, 25])\n\n> nj.arange(1, 5, 'uint8');\narray([ 1, 2, 3, 4], dtype=uint8)\n```\n\n### More info about the array\n\n__NumJs__’s array class is called `NdArray`. It is also known by the alias `array`. The more important properties of an `NdArray` object are:\n - `NdArray#ndim`: the number of axes (dimensions) of the array.\n - `NdArray#shape`: the dimensions of the array. This is a list of integers indicating the size of the array in each dimension. For a matrix with n rows and m columns, shape will be [n,m]. The length of the shape is therefore the number of dimensions, ndim.\n - `NdArray#size`: the total number of elements of the array. This is equal to the product of the elements of shape.\n - `NdArray#dtype`: a string describing the type of the elements in the array. `int32`, `int16`, and `float64` are some examples. Default dtype is `array`.\n\nAn `NdArray` can always be converted to a native JavaScript `Array` using `NdArray#tolist()` method.\n\n\nExample:\n```js\n> a = nj.arange(15).reshape(3, 5);\narray([[  0,  1,  2,  3,  4],\n       [  5,  6,  7,  8,  9],\n       [ 10, 11, 12, 13, 14]])\n\n> a.shape\n[ 3, 5]\n> a.ndim\n2\n> a.dtype\n'array'\n> a instanceof nj.NdArray\ntrue\n> a.tolist() instanceof Array\ntrue\n> a.get(1,1)\n6\n> a.set(0,0,1)\n> a\narray([[  1,  1,  2,  3,  4],\n       [  5,  6,  7,  8,  9],\n       [ 10, 11, 12, 13, 14]])\n\n```\n\n### Printing arrays\n\nWhen you print an array, __NumJs__ displays it in a similar way to nested lists, but with the following layout:\n - the last axis is printed from left to right,\n - the second-to-last is printed from top to bottom,\n - the rest are also printed from top to bottom, with each slice separated from the next by an empty line.\n\nOne-dimensional arrays are then printed as rows, bidimensionals as matrices and tridimensionals as lists of matrices.\n\n```js\n> var a = nj.arange(6);                 // 1d array\n> console.log(a);\narray([ 0, 1, 2, 3, 4, 5])\n>\n> var b = nj.arange(12).reshape(4,3);   // 2d array\n> console.log(b);\narray([[  0,  1,  2],\n       [  3,  4,  5],\n       [  6,  7,  8],\n       [  9, 10, 11]])\n>\n> var c = nj.arange(24).reshape(2,3,4); // 3d array\n> console.log(c);\narray([[[  0,  1,  2,  3],\n        [  4,  5,  6,  7],\n        [  8,  9, 10, 11]],\n       [[ 12, 13, 14, 15],\n        [ 16, 17, 18, 19],\n        [ 20, 21, 22, 23]]])\n\n```\n\nIf an array is too large to be printed, __NumJs__ automatically skips the central part of the array and only prints the corners:\n\n```js\n> console.log(nj.arange(10000).reshape(100,100))\narray([[    0,    1, ...,   98,   99],\n       [  100,  101, ...,  198,  199],\n        ...\n       [ 9800, 9801, ..., 9898, 9899],\n       [ 9900, 9901, ..., 9998, 9999]])\n```\n\nTo customize this behaviour, you can change the printing options using `nj.config.printThreshold` (default is `7`):\n```js\n> nj.config.printThreshold = 9;\n> console.log(nj.arange(10000).reshape(100,100))\narray([[    0,    1,    2,    3, ...,   96,   97,   98,   99],\n       [  100,  101,  102,  103, ...,  196,  197,  198,  199],\n       [  200,  201,  202,  203, ...,  296,  297,  298,  299],\n       [  300,  301,  302,  303, ...,  396,  397,  398,  399],\n        ...\n       [ 9600, 9601, 9602, 9603, ..., 9696, 9697, 9698, 9699],\n       [ 9700, 9701, 9702, 9703, ..., 9796, 9797, 9798, 9799],\n       [ 9800, 9801, 9802, 9803, ..., 9896, 9897, 9898, 9899],\n       [ 9900, 9901, 9902, 9903, ..., 9996, 9997, 9998, 9999]])\n\n```\n\n### Indexing\n\nSingle element indexing  uses `get` and `set` methods. It is 0-based, and accepts negative indices for indexing from the end of the array:\n```js\n> var a = nj.array([0,1,2]);\n> a.get(1)\n1\n>\n> a.get(-1)\n2\n>\n> var b = nj.arange(3*3).reshape(3,3);\n> b\narray([[  0,  1,  2],\n       [  3,  4,  5],\n       [  6,  7,  8])\n>\n> b.get(1, 1);\n4\n>\n> b.get(-1, -1);\n8\n> b.set(0,0,1);\n> b\narray([[ 1, 1, 2],\n       [ 3, 4, 5],\n       [ 6, 7, 8]])\n```\n\n\n### Slicing and Striding\n\nIt is possible to slice and stride arrays to extract arrays of the same number of dimensions, but of different sizes than the original. The slicing and striding works exactly the same way it does in NumPy:\n\n```js\n> var a = nj.arange(5);\n> a\narray([  0,  1,  2,  3,  4])\n>\n> a.slice(1) // skip the first item, same as a[1:]\narray([ 1, 2, 3, 4])\n>\n> a.slice(-3) // takes the last 3 items, same as a[-3:]\narray([ 2, 3, 4])\n>\n> a.slice([4]) // takes the first 4 items, same as a[:4]\narray([ 0, 1, 2, 3])\n>\n> a.slice([-2]) // skip the last 2 items, same as a[:-2]\narray([ 0, 1, 2])\n>\n> a.slice([1,4]) // same as a[1:4]\narray([ 1, 2, 3])\n>\n> a.slice([1,4,-1]) // same as a[1:4:-1]\narray([ 3, 2, 1])\n>\n> a.slice([null,null,-1]) // same as a[::-1]\narray([ 4, 3, 2, 1, 0])\n>\n> var b = nj.arange(5*5).reshape(5,5);\n> b\narray([[  0,  1,  2,  3,  4],\n       [  5,  6,  7,  8,  9],\n       [ 10, 11, 12, 13, 14],\n       [ 15, 16, 17, 18, 19],\n       [ 20, 21, 22, 23, 24]])\n>\n> b.slice(1,2) //  skip the first row and the 2 first  columns, same as b[1:,2:]\narray([[  7,  8,  9],\n       [ 12, 13, 14],\n       [ 17, 18, 19],\n       [ 22, 23, 24]])\n>\n> b.slice(null, [null, null, -1]) // reverse rows, same as b[:, ::-1]\narray([[  4,  3,  2,  1,  0],\n       [  9,  8,  7,  6,  5],\n       [ 14, 13, 12, 11, 10],\n       [ 19, 18, 17, 16, 15],\n       [ 24, 23, 22, 21, 20]])\n```\n\nNote that slices do not copy the internal array data, it produces a new views of the original data.\n\n### Basic operations\n\nArithmetic operators such as `*` (`multiply`), `+` (`add`), `-` (`subtract`), `/` (`divide`), `**` (`pow`), `=` (`assign`) apply elemen-twise. A new array is created and filled with the result:\n\n```js\n> zeros = nj.zeros([3,4]);\narray([[ 0, 0, 0, 0],\n       [ 0, 0, 0, 0],\n       [ 0, 0, 0, 0]])\n>\n> ones = nj.ones([3,4]);\narray([[ 1, 1, 1, 1],\n       [ 1, 1, 1, 1],\n       [ 1, 1, 1, 1]])\n>\n> ones.add(ones)\narray([[ 2, 2, 2, 2],\n       [ 2, 2, 2, 2],\n       [ 2, 2, 2, 2]])\n>\n> ones.subtract(ones)\narray([[ 0, 0, 0, 0],\n       [ 0, 0, 0, 0],\n       [ 0, 0, 0, 0]])\n>\n> zeros.pow(zeros)\narray([[ 1, 1, 1, 1],\n       [ 1, 1, 1, 1],\n       [ 1, 1, 1, 1]])\n>\n```\n\nTo modify an existing array rather than create a new one you can set the `copy` parameter to `false`:\n\n```js\n> ones = nj.ones([3,4]);\narray([[ 1, 1, 1, 1],\n       [ 1, 1, 1, 1],\n       [ 1, 1, 1, 1]])\n>\n> ones.add(ones, false)\narray([[ 2, 2, 2, 2],\n       [ 2, 2, 2, 2],\n       [ 2, 2, 2, 2]])\n>\n> ones\narray([[ 2, 2, 2, 2],\n       [ 2, 2, 2, 2],\n       [ 2, 2, 2, 2]])\n>\n> zeros = nj.zeros([3,4])\n> zeros.slice([1,-1],[1,-1]).assign(1, false);\n> zeros\narray([[ 0, 0, 0, 0],\n       [ 0, 1, 1, 0],\n       [ 0, 0, 0, 0]])\n```\n__Note__: available for `add`, `subtract`, `multiply`, `divide`, `assign` and `pow` methods.\n\n\nThe matrix product can be performed using the `dot` function:\n\n```js\n> a = nj.arange(12).reshape(3,4);\narray([[  0,  1,  2,  3],\n       [  4,  5,  6,  7],\n       [  8,  9, 10, 11]])\n>\n> nj.dot(a.T, a)\narray([[  80,  92, 104, 116],\n       [  92, 107, 122, 137],\n       [ 104, 122, 140, 158],\n       [ 116, 137, 158, 179]])\n>\n> nj.dot(a, a.T)\narray([[  14,  38,  62],\n       [  38, 126, 214],\n       [  62, 214, 366]])\n```\n\nMany unary operations, such as computing the sum of all the elements in the array, are implemented as methods of the `NdArray` class:\n\n```js\n> a = nj.random([2,3])\narray([[0.62755, 0.8278,0.21384],\n       [ 0.7029,0.27584,0.46472]])\n> a.sum()\n3.1126488673035055\n>\n> a.min()\n0.2138431086204946\n>\n> a.max()\n0.8278025290928781\n>\n> a.mean()\n0.5187748112172509\n>\n> a.std()\n0.22216977543691244\n```\n\n### Universal Functions\n__NumJs__ provides familiar mathematical functions such as `sin`, `cos`, and `exp`. These functions operate element-wise on an array, producing an `NdArray` as output:\n\n```js\n> a = nj.array([-1, 0, 1])\narray([-1, 0, 1])\n>\n> nj.negative(a)\narray([ 1, 0,-1])\n>\n> nj.abs(a)\narray([ 1, 0, 1])\n>\n> nj.exp(a)\narray([ 0.36788,       1, 2.71828])\n>\n> nj.tanh(a)\narray([-0.76159,       0, 0.76159])\n>\n> nj.softmax(a)\narray([ 0.09003, 0.24473, 0.66524])\n>\n> nj.sigmoid(a)\narray([ 0.26894,     0.5, 0.73106])\n>\n> nj.exp(a)\narray([ 0.36788,       1, 2.71828])\n>\n> nj.log(nj.exp(a))\narray([-1, 0, 1])\n>\n> nj.sqrt(nj.abs(a))\narray([ 1, 0, 1])\n>\n> nj.sin(nj.arcsin(a))\narray([-1, 0, 1])\n>\n> nj.cos(nj.arccos(a))\narray([-1, 0, 1])\n>\n> nj.tan(nj.arctan(a))\narray([-1, 0, 1])\n```\n\n### Shape Manipulation\nAn array has a shape given by the number of elements along each axis:\n\n```js\n> a = nj.array([[  0,  1,  2,  3], [  4,  5,  6,  7], [  8,  9, 10, 11]]);\narray([[  0,  1,  2,  3],\n       [  4,  5,  6,  7],\n       [  8,  9, 10, 11]])\n\n> a.shape\n[ 3, 4 ]\n```\n\nThe shape of an array can be changed with various commands:\n```js\n> a.flatten();\narray([  0,  1,  2, ...,  9, 10, 11])\n>\n> a.T                   // equivalent to a.transpose(1,0)\narray([[  0,  4,  8],\n       [  1,  5,  9],\n       [  2,  6, 10],\n       [  3,  7, 11]])\n>\n> a.reshape(4,3)\narray([[  0,  1,  2],\n       [  3,  4,  5],\n       [  6,  7,  8],\n       [  9, 10, 11]])\n>\n```\n\nSince `a` is matrix we may want its diagonal:\n```js\n> nj.diag(a)\narray([  0,  5, 10])\n>\n```\n\n### Identity matrix\nThe identity array is a square array with ones on the main diagonal:\n\n```js\n> nj.identity(3)\narray([[ 1, 0, 0],\n       [ 0, 1, 0],\n       [ 0, 0, 1]])\n```\n\n### Concatenate different arrays\n\nSeveral arrays can be stacked together using `concatenate` function:\n\n```js\n> a = nj.arange(12).reshape(3,4)\narray([[  0,  1,  2,  3],\n       [  4,  5,  6,  7],\n       [  8,  9, 10, 11]])\n>\n> b = nj.arange(3)\narray([ 0, 1, 2])\n>\n> nj.concatenate(a,b.reshape(3,1))\narray([[  0,  1,  2,  3,  0],\n       [  4,  5,  6,  7,  1],\n       [  8,  9, 10, 11,  2]])\n```\n\n__Notes__:\n - the arrays must have the same shape, except in the last dimension\n - arrays are concatenated along the last axis\n\nIt is still possible to concatenate along other dimensions using transpositions:\n\n```js\n> a = nj.arange(12).reshape(3,4)\narray([[  0,  1,  2,  3],\n       [  4,  5,  6,  7],\n       [  8,  9, 10, 11]])\n>\n> b = nj.arange(4)\narray([ 0, 1, 2, 3])\n>\n> nj.concatenate(a.T,b.reshape(4,1)).T\narray([[  0,  1,  2,  3],\n       [  4,  5,  6,  7],\n       [  8,  9, 10, 11],\n       [  0,  1,  2,  3]])\n```\n\n\n### Stack multiple arrays\n\n```js\n> a = nj.array([1, 2, 3])\n> b = nj.array([2, 3, 4])\n\n> np.stack([a, b])\narray([[1, 2, 3],\n       [2, 3, 4]])\n> np.stack([a, b], -1)\narray([[1, 2],\n       [2, 3],\n       [3, 4]])\n```\n\n__Notes__:\n - the arrays must have the same shape\n - take an optional axis argument which can be negative\n\n### Deep Copy\nThe `clone` method makes a complete copy of the array and its data.\n\n```js\n> a = nj.arange(12).reshape(3,4)\narray([[  0,  1,  2,  3],\n       [  4,  5,  6,  7],\n       [  8,  9, 10, 11]])\n>\n> b = a.clone()\narray([[  0,  1,  2,  3],\n       [  4,  5,  6,  7],\n       [  8,  9, 10, 11]])\n>\n> a === b\nfalse\n>\n> a.set(0,0,1)\n> a\narray([[  1,  1,  2,  3],\n       [  4,  5,  6,  7],\n       [  8,  9, 10, 11]])\n> b\narray([[  0,  1,  2,  3],\n       [  4,  5,  6,  7],\n       [  8,  9, 10, 11]])\n```\n\n### Fast Fourier Transform (FFT)\n`fft` and `ifft` functions can be used to compute the N-dimensional discrete Fourier Transform and its inverse.\n\nExample:\n```js\n> RI = nj.concatenate(nj.ones([10,1]), nj.zeros([10,1]))\narray([[ 1, 0],\n       [ 1, 0],\n       [ 1, 0],\n        ...\n       [ 1, 0],\n       [ 1, 0],\n       [ 1, 0]])\n>\n> fft = nj.fft(RI)\narray([[ 10,  0],\n       [  0,  0],\n       [  0,  0],\n        ...\n       [  0,  0],\n       [  0,  0],\n       [  0,  0]])\n>\n> nj.ifft(fft)\narray([[ 1, 0],\n       [ 1, 0],\n       [ 1, 0],\n        ...\n       [ 1, 0],\n       [ 1, 0],\n       [ 1, 0]])\n```\n__Note__: both `fft` and `ifft` expect last dimension of the array to contain 2 values: the real and the imaginary value\n\n\n### Convolution\n\n`convolve` function compute the discrete, linear convolution of two multi-dimensional arrays.\n\n__Note__: The convolution product is only given for points where the signals overlap completely. Values outside the signal boundary have no effect. This behaviour is also known as the 'valid' mode.\n\n\nExample:\n```js\n> x = nj.array([0,0,1,2,1,0,0])\narray([ 0, 0, 1, 2, 1, 0, 0])\n>\n> nj.convolve(x, [-1,0,1])\narray([-1,-2, 0, 2, 1])\n>\n> var a = nj.arange(25).reshape(5,5)\n> a\narray([[  0,  1,  2,  3,  4],\n       [  5,  6,  7,  8,  9],\n       [ 10, 11, 12, 13, 14],\n       [ 15, 16, 17, 18, 19],\n       [ 20, 21, 22, 23, 24]])\n> nj.convolve(a, [[ 1, 2, 1], [ 0, 0, 0], [-1,-2,-1]])\narray([[ 40, 40, 40],\n       [ 40, 40, 40],\n       [ 40, 40, 40]])\n> nj.convolve(nj.convolve(a, [[1, 2, 1]]), [[1],[0],[-1]])\narray([[ 40, 40, 40],\n       [ 40, 40, 40],\n       [ 40, 40, 40]])\n```\n\n__Note__: `convolve` uses Fast Fourier Transform (FFT) to speed up computation on large arrays.\n\n\n### Other utils\n`rot90`\n```js\n> m = nj.array([[1,2],[3,4]], 'int')\n> m\narray([[1, 2],\n       [3, 4]])\n> nj.rot90(m)\narray([[2, 4],\n       [1, 3]])\n> nj.rot90(m, 2)\narray([[4, 3],\n       [2, 1]])\n> m = nj.arange(8).reshape([2,2,2])\n> nj.rot90(m, 1, [1,2])\narray([[[1, 3],\n        [0, 2]],\n      [[5, 7],\n       [4, 6]]])\n```\n\n`mod` (since v0.16.0)\n```js\n> nj.mod(nj.arange(7), 5)\n> m\narray([0, 1, 2, 3, 4, 0, 1])\n```\n\n\n## Images manipulation\n__NumJs__’s comes with powerful functions for image processing. Theses function are located in `nj.images` module.\n\nThe different color bands/channels are stored using the `NdArray` object such that a grey-image is `[H,W]`, an RGB-image is `[H,W,3]` and an RGBA-image is `[H,W,4]`.\n\nUse `nj.images.read`, `nj.images.write` and `nj.images.resize` functions to (respectively) read, write or resize images.\n\nExample:\n```js\n> nj.config.printThreshold = 28;\n>\n> var img = nj.images.data.digit;  // WARN: this is a property, not a function. See also `nj.images.data.moon`, `nj.images.data.lenna` and `nj.images.data.node`\n>\n> img\narray([[   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0],\n       [   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0],\n       [   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0],\n       [   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0],\n       [   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0],\n       [   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   3,  18,  18,  18, 126, 136, 175,  26, 166, 255, 247, 127,   0,   0,   0,   0],\n       [   0,   0,   0,   0,   0,   0,   0,   0,  30,  36,  94, 154, 170, 253, 253, 253, 253, 253, 225, 172, 253, 242, 195,  64,   0,   0,   0,   0],\n       [   0,   0,   0,   0,   0,   0,   0,  49, 238, 253, 253, 253, 253, 253, 253, 253, 253, 251,  93,  82,  82,  56,  39,   0,   0,   0,   0,   0],\n       [   0,   0,   0,   0,   0,   0,   0,  18, 219, 253, 253, 253, 253, 253, 198, 182, 247, 241,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0],\n       [   0,   0,   0,   0,   0,   0,   0,   0,  80, 156, 107, 253, 253, 205,  11,   0,  43, 154,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0],\n       [   0,   0,   0,   0,   0,   0,   0,   0,   0,  14,   1, 154, 253,  90,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0],\n       [   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 139, 253, 190,   2,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0],\n       [   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,  11, 190, 253,  70,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0],\n       [   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,  35, 241, 225, 160, 108,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0],\n       [   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,  81, 240, 253, 253, 119,  25,   0,   0,   0,   0,   0,   0,   0,   0,   0],\n       [   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,  45, 186, 253, 253, 150,  27,   0,   0,   0,   0,   0,   0,   0,   0],\n       [   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,  16,  93, 252, 253, 187,   0,   0,   0,   0,   0,   0,   0,   0],\n       [   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 249, 253, 249,  64,   0,   0,   0,   0,   0,   0,   0],\n       [   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,  46, 130, 183, 253, 253, 207,   2,   0,   0,   0,   0,   0,   0,   0],\n       [   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,  39, 148, 229, 253, 253, 253, 250, 182,   0,   0,   0,   0,   0,   0,   0,   0],\n       [   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,  24, 114, 221, 253, 253, 253, 253, 201,  78,   0,   0,   0,   0,   0,   0,   0,   0,   0],\n       [   0,   0,   0,   0,   0,   0,   0,   0,  23,  66, 213, 253, 253, 253, 253, 198,  81,   2,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0],\n       [   0,   0,   0,   0,   0,   0,  18, 171, 219, 253, 253, 253, 253, 195,  80,   9,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0],\n       [   0,   0,   0,   0,  55, 172, 226, 253, 253, 253, 253, 244, 133,  11,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0],\n       [   0,   0,   0,   0, 136, 253, 253, 253, 212, 135, 132,  16,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0],\n       [   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0],\n       [   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0],\n       [   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0]], dtype=uint8)\n> var resized = nj.images.resize(img, 14, 12)\n>\n> resized.shape\n[ 14, 12 ]\n>\n> resized\narray([[   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0],\n       [   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0],\n       [   0,   0,   0,   0,   0,   6,   9,  66,  51, 106,  94,   0],\n       [   0,   0,  13, 140, 189, 233, 253, 253, 143, 159,  75,   0],\n       [   0,   0,   5, 178, 217, 241,  98, 172,   0,   0,   0,   0],\n       [   0,   0,   0,   4,  74, 197,   1,   0,   0,   0,   0,   0],\n       [   0,   0,   0,   0,   3, 180, 114,  28,   0,   0,   0,   0],\n       [   0,   0,   0,   0,   0,  21, 182, 220,  51,   0,   0,   0],\n       [   0,   0,   0,   0,   0,   0,   4, 149, 236,  16,   0,   0],\n       [   0,   0,   0,   0,   0,  47, 165, 236, 224,   1,   0,   0],\n       [   0,   0,   0,  23, 152, 245, 240, 135,  20,   0,   0,   0],\n       [   0,  57, 167, 245, 251, 148,  23,   0,   0,   0,   0,   0],\n       [   0,  98, 127,  87,  37,   0,   0,   0,   0,   0,   0,   0],\n       [   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0]], dtype=uint8)\n```\n\nSee also [this jsfiddle](https://jsfiddle.net/nicolaspanel/047gwg0q/) for more details on what is possible from the browser.\n\n\n## More ?\nSee documentation on [numjs globals](http://nicolaspanel.github.io/numjs/global.html) and\n[NdArray methods](http://nicolaspanel.github.io/numjs/NdArray.html).\n\n\n\n## Credits\n__NumJs__ is built on top of [ndarray](http://scijs.net/packages/#scijs/ndarray) and uses many [scijs packages](http://scijs.net/packages/)\n","readmeFilename":"README.md"}