nicolaspanel / numjs

Like NumPy, in JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reshape Not allowing resizing

MasterJames opened this issue · comments

Doing a little REPL testing I found the reshape commend is not working.

> let rangeArray = np.arange(6,12)
> rangeArray
array([  6,  7,  8,  9, 10, 11])

> rangeArray.reshape( (2,3) )
ValueError: total size of new array must be unchanged
    at new ValueError (./node_modules/numjs/src/errors.js:5:21)
    at NdArray.reshape (./node_modules/numjs/src/ndarray.js:260:11)
> rangeArray.size
6
> rangeArray.reshape( (1,6) )
array([  6,  7,  8,  9, 10, 11])
> rangeArray.reshape( (6,1) )
ValueError: total size of new array must be unchanged
    at new ValueError (./node_modules/numjs/src/errors.js:5:21)
    at NdArray.reshape (./node_modules/numjs/src/ndarray.js:260:11)

It is JavaScript, not python ;)
See https://github.com/nicolaspanel/numjs/blob/master/test/mocha/reshape.spec.js for working examples

Right sorry thanks for taking the time. I'm just looking through a python tutorial and wanting to use JavaScript so I overlooked it being an eager noob.
square brackets also works in reshape, great!

> let ra = np.arange(6,12)
> ra
array([  6,  7,  8,  9, 10, 11])
> ra.reshape( (2,3) )
ValueError: total size of new array must be unchanged
    at new ValueError (./node_modules/numjs/src/errors.js:5:21)
    at NdArray.reshape (./node_modules/numjs/src/ndarray.js:260:11)
> ra.reshape( [2,3] )
array([[  6,  7,  8],
       [  9, 10, 11]])
> ra.reshape( 2,3 )
array([[  6,  7,  8],
       [  9, 10, 11]])