Comments (6)
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.
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.
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.
Yes, .slice()
works for me either. Thank you very much for all these information.
from ndarray.
Btw, are there any better modules to let me perform these operations as smoothly as pytorch?
from ndarray.
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)
- Docs should say that hi/lo accept nulls HOT 7
- Docs for hi/lo are confusing HOT 8
- Docs for transpose are wrong HOT 2
- Dot product HOT 3
- Buffer problems
- load a series of images as a volume HOT 1
- How to convert an ndarray back to a buffer/array/…? HOT 2
- Any standard way to `unindex` ? HOT 2
- deleted
- ndarray.set the i, j vector HOT 4
- Code generation HOT 3
- Convert to JS Array? HOT 6
- ndarray not getting value as expected. HOT 2
- Validate input for get method (and others potentially)
- GPU support HOT 1
- Use Proxies to make indexable ndarrays HOT 5
- implementing ndarray in C++ for performance HOT 2
- hi and lo are behaving unexpectedly
- Is it possible to pick an angled slice out of a 3D array?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ndarray.