Coder Social home page Coder Social logo

zeros's Introduction

zeros

A replacement for ndarray.zeros (which was removed in ndarray 1.0.0)

Example

var zeros = require("zeros")

//Creates a 64x64 ndarray over a float64array filled with 0
var x = zeros([64, 64])

It also accepts an optional dtype as specified in the ndarray docs. For example,

//Creates a 64x64 ndarray over a float32array filled with 0
var x = zeros([64, 64], 'float32')

This makes it easy to create an array with the same size and dtype as an existing array:

var x = zeros([64, 64], 'float32')
var y = zeros( x.shape, x.dtype )

If you find yourself frequently creating the same array over and over though, ndarray-scratch may be a better option.

Install

Just use npm:

npm install zeros

require("zeros")(shape[, dtype])

Creates an ndarray with the given shape that is initialized to zero

  • shape is the shape of the resulting array
  • dtype is the data type of the array to allocate. Must be one of:
    • "array"
    • "uint8"
    • "uint16"
    • "uint32"
    • "int8"
    • "int16"
    • "int32"
    • "float"
    • "float32"
    • "double"
    • "float64"
    • "data"
    • "uint8_clamped"
    • "buffer"

Returns An array which is initialized to 0

Credits

(c) 2013 Mikola Lysenko. MIT License

zeros's People

Contributors

mikolalysenko avatar rreusser avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

shama

zeros's Issues

Specification of dtype

It would be nice if it were possible to pass a dtype to zeros. This would make it possible to say:

z = zeros( existingArray.shape, dtype='uint16' )

It seems like inclusion of typedarray-pool as a dependency would make this pretty straightforward, but it's more than necessary. All that's really needed is a function that translates the dtype string to a constructor.

In lieu of this (or if I'm missing the way to do this), is there a good way to construct an ndarray with the same shape and datatype as an existing array? I could leave construction of all work arrays to the user, but that's more than a little cumbersome.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.