Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

array-normalize

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

array-normalize - npm Package Compare versions

Comparing version 1.1.1 to 1.1.2

.npmignore

12

index.js
'use strict'
var getBounds = require('array-bounds')
module.exports = normalize;
function normalize (arr, dim) {
function normalize (arr, dim, bounds) {
if (!arr || arr.length == null) throw Error('Argument should be an array')
if (dim == null) dim = 1
if (bounds == null) bounds = getBounds(arr, dim)
for (var offset = 0; offset < dim; offset++) {
var max = -Infinity, min = Infinity, i = offset, l = arr.length;
var max = bounds[dim + offset], min = bounds[offset], i = offset, l = arr.length;
for (; i < l; i+=dim) {
if (arr[i] > max) max = arr[i];
if (arr[i] < min) min = arr[i];
}
if (max === Infinity && min === -Infinity) {

@@ -19,0 +17,0 @@ for (i = offset; i < l; i+=dim) {

{
"name": "array-normalize",
"version": "1.1.1",
"version": "1.1.2",
"description": "Normalize array (possibly n-dimensional) to zero mean and unit variance",

@@ -25,3 +25,6 @@ "main": "index.js",

},
"homepage": "https://github.com/dfcreative/array-normalize#readme"
"homepage": "https://github.com/dfcreative/array-normalize#readme",
"dependencies": {
"array-bounds": "^1.0.0"
}
}
# array-normalize [![experimental](https://img.shields.io/badge/stability-unstable-yellow.svg)](http://github.com/badges/stability-badges) [![Build Status](https://img.shields.io/travis/dfcreative/array-normalize.svg)](https://travis-ci.org/dfcreative/array-normalize)
Normalize array in-place to zero mean and unit variance.
Normalize array to unit length, that is 0..1 range. See [feature scaling](https://en.wikipedia.org/wiki/Feature_scaling).

@@ -15,4 +15,4 @@ [![npm install array-normalize](https://nodei.co/npm/array-normalize.png?mini=true)](https://npmjs.org/package/array-normalize/)

### array = normalize(array, n=1)
### array = normalize(array, n=1, bounds?)
Normalizes n-dimensional array in-place using dimensions `n` as stride, ie. for 1d array the expected data layout is `[x, x, x, ...]` for 2d is `[x, y, x, y, ...]`, etc. Every dimension is normalized independently, so 2d array is normalized to unit square `[0, 0, 1, 1]`.
Normalizes n-dimensional array in-place using dimensions `n` as stride, ie. for 1d array the expected data layout is `[x, x, x, ...]` for 2d is `[x, y, x, y, ...]`, etc. Every dimension is normalized independently, so 2d array is normalized to unit square `[0, 0, 1, 1]`. Optionally pass `bounds` box if you know min/max values to optimize calculations.

@@ -5,2 +5,3 @@ 'use strict'

const assert = require('assert')
const getBounds = require('array-bounds')

@@ -18,1 +19,4 @@ let a = [-Infinity, -1, 0, 1, Infinity]

assert.deepEqual(norm(d.slice(), 2), [0, 0, .1, .1, 1, 1])
let e = [0, 0, .1, .2, 1, 2]
assert.deepEqual(norm(e.slice(), 2, getBounds(e, 2)), [0, 0, .1, .1, 1, 1])
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc