Skip to content

Array conversion and memory layout #607

Answered by cjdoris
maxfreu asked this question in Q&A
Discussion options

You must be logged in to vote

While you're right about the memory layout by default, both Julia and Numpy can happily handle arrays with other layouts - in particular they can both handle arrays with arbitrary strides.

Hence PythonCall does the most obvious thing and preserves the array's shape and order of dimensions by representing a Julia column-major array as a strided array in Numpy.

In practice it's common that you do actually want to reverse the order of the dimensions when going between Julia and Python precisely because of this ordering difference, which you can do with basically no overhead by transposing the array either before or after the conversion.

Replies: 1 comment 1 reply

Comment options

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

Answer selected by maxfreu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants