Git Product home page Git Product logo

Comments (6)

rreusser avatar rreusser commented on August 11, 2024

It doesn't have reshape() exactly, but you might be able to use the constructor ndarray(data[, shape, stride, offset]):

a = ndarray([1, 2, 3, 4], [2, 2])

b = ndarray(a.data, [4])

This will probably work perfectly well for simple cases where the array is not already a stepped or transposed view, but be advised that stride and offset are capable of representing memory layouts which may not be completely straightforward to reinterpret with a different shape. When I know what the input l looks like though, I've frequently used this approach.

TBH it does seem like a bit of missing functionality to do this with strict checking so that you know the result is valid.

from ndarray.

cxchhh avatar cxchhh commented on August 11, 2024

That's what I need, thanks.
However, after b = ndarray(a.data, [4]), it seems that b.data and a.data are bind together. When I change b.data, a.data changes as well.
Try this:

var a=zeros([1],'float32');
var b=ndarray(a.data,a.shape);
b.set(0,1);
console.log(a);
console.log(b);

you'll see that both a.data and b.data = [1]. That's weird.

from ndarray.

rreusser avatar rreusser commented on August 11, 2024

Yes, you can always call .slice() on the data array if you want to decouple them. You'll find that, in general, copying memory is the exception rather than the norm when using scijs/ndarray. This differs from matlab or numpy which tend to copy the memory on every operation. Also, in case you haven't seen it, ndarray-ops may be a useful set of functions, and I wrote this many years ago as well: https://github.com/scijs/scijs-ndarray-for-matlab-users

from ndarray.

cxchhh avatar cxchhh commented on August 11, 2024

Yes, .slice() works for me either. Thank you very much for all these information.

from ndarray.

cxchhh avatar cxchhh commented on August 11, 2024

Btw, are there any better modules to let me perform these operations as smoothly as pytorch?

from ndarray.

rreusser avatar rreusser commented on August 11, 2024

The only other module I know of is stdlib/ndarray. The Stdlib project is aiming to be much closer to numpy ndarrays, both in terms of design and extensibility, but although it's a much more complete foundation, it doesn't yet have an ecosystem of tools around it. I'm not too familiar with tensorflow, but if your interest is in ML, those toolkits might have more to offer than scijs/ndarray.

from ndarray.

Related Issues (20)

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.