dpilger26 / NumCpp

C++ implementation of the Python Numpy library
https://dpilger26.github.io/NumCpp
MIT License
3.56k stars 555 forks source link

zeros returns different shape to lumpy #118

Closed conradjones closed 2 years ago

conradjones commented 3 years ago

I'm seeing different behaviour from NumCpp for Numpy for zeros, is this expected ?

import numpy v = numpy.zeros(8) print(v)

outputs

[0. 0. 0. 0. 0. 0. 0. 0.]


auto w = nc::zeros<float>(len); std::cout << w << "\n";

outputs

[[0, 0, 0, 0, 0, 0, 0, 0, ] [0, 0, 0, 0, 0, 0, 0, 0, ] [0, 0, 0, 0, 0, 0, 0, 0, ] [0, 0, 0, 0, 0, 0, 0, 0, ] [0, 0, 0, 0, 0, 0, 0, 0, ] [0, 0, 0, 0, 0, 0, 0, 0, ] [0, 0, 0, 0, 0, 0, 0, 0, ] [0, 0, 0, 0, 0, 0, 0, 0, ]]

dpilger26 commented 3 years ago

That's correct, see the documentation here.

If you would like a 1D array then you can use either of the other two overloads for zeros() as documented here.

auto w = nc::zeros<float>(1, len);  // rows and cols size overload

or

auto w = nc::zeros<float>({1, len}); // Shape overload