15
flossn
7y

What I have: [a, b, c]
What I need: [[a],[b],[c]]
No documentation
Just numpy things ¯\_(ツ)_/¯

Comments
  • 0
    An array[3] of array[1]s?
  • 1
    Jep, reshaping to (-1,1) was the solution. But it caused some random exception that made it a pain to debug.
  • 1
    Welcome!
  • 0
    JavaScript

    const arr = [ a, b, c ]
    const newArr = arr.map((val) => [ val ])
  • 1
    Numpy does have some docs. I think they assume you'd just loop through your array and make new items that way.

    Thanks to their *fantastic* docs, I re-wrote my senior project three times. I didn't notice they'd mirrored the coordinates intentionally. :/
  • 0
    not sure what numpy has but in general I'd say
    option 1 : map
    option 2 : forEach
  • 0
    @flossn "reshaping to (-1,1)" what the heck does that mean?

    and what kind of weird environment is this where you can't just iterate an array?
  • 1
    @jiraTicket numpy has strange (matlab) syntax and because of the way python handles typing, iterations can get kind of weird if you aren't exactly sure what's going on.

    If you explicitly iterate through a whole list, you can really slow things down, too, since you aren't using the bits that are in C, you're using something at native python speed. 'Pythonic' code matters for performance reasons as well as aesthetic ones.
  • 0
    @jiraTicket It basically means reshaping a one dimensional array [a,b,c] to a two dimensional array [[a],[... with a variable sized first axis (-1) and a fixed (in this case one) sized second axis (1)
Add Comment