Skip to content

vector.array method has unexpected behavior with lists of lists vs. tuples #342

Answered by Saransh-cpp
denehoffman asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks for pointing this out! I think this should be the intended behavior given that numpy works with structured arrays in a similar way -

In [1]: v = np.array([[1.1, 2.1], [1.2, 2.2], [1.3, 2.3], [1.4, 2.4], [1.5, 2.5]
   ...: ], dtype=[('x', float), ('y', float)])

In [2]: v
Out[2]: 
array([[(1.1, 1.1), (2.1, 2.1)],
       [(1.2, 1.2), (2.2, 2.2)],
       [(1.3, 1.3), (2.3, 2.3)],
       [(1.4, 1.4), (2.4, 2.4)],
       [(1.5, 1.5), (2.5, 2.5)]], dtype=[('x', '<f8'), ('y', '<f8')])

Moreover, VectorNumpy classes internally call numpy.array and pass a view of it to the users; hence, the behavior stays intact -

class

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@denehoffman
Comment options

Answer selected by Saransh-cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
bug (unverified) The problem described would be a bug, but needs to be triaged
2 participants
Converted from issue

This discussion was converted from issue #341 on May 02, 2023 18:39.