Git Product home page Git Product logo

Comments (3)

mikolalysenko avatar mikolalysenko commented on August 11, 2024

You can easily write on yourself, but the reason that no reshape operations are supported currently is that such a thing would require reallocating the underlying array. For example, to reshape a 2D array into a 1D array you could do something like:

var x = ndarray(y.data, [y.shape[0] * y.shape[1]])

Of course this only works if y is packed tightly and if y's offset is 0.

from ndarray.

letmaik avatar letmaik commented on August 11, 2024

What's the problem with reallocation? My use case is to access all elements of an ndarray irrespective of its shape, and I don't know how to do that (array is a subset) as there is also no flatten/ravel function.

from ndarray.

enobufs avatar enobufs commented on August 11, 2024

I was looking for reshape() operation for ndarray, then came across this old issue...

such a thing would require reallocating the underlying array

The in-place reshape I wish to have, is like the one by numpy, would not change the underlying array. Why would it require reallocation of underlying array??

>>> import numpy as np
>>> np.array([1, 2, 3, 4, 5, 6])
array([1, 2, 3, 4, 5, 6])
>>> a = np.array([1, 2, 3, 4, 5, 6])
>>> a
array([1, 2, 3, 4, 5, 6])
>>> a.reshape(2, 3)
array([[1, 2, 3],
       [4, 5, 6]])
>>> a.reshape(3, 2)
array([[1, 2],
       [3, 4],
       [5, 6]])
>>> a.reshape(3, 3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: cannot reshape array of size 6 into shape (3,3)
>>> a.reshape(6)
array([1, 2, 3, 4, 5, 6])

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.