2

In a programming quiz I came accross the flags attribute for numpy arrays in Python and I was wondering was the output all means. After reading https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.flags.html, I don't really understand some of the output. What do C_CONTIGUOUS, F_CONTIGUOUS, ALIGNED and UPDATEIFCOPY mean, explained without as much jargon as the documentation?

import numpy as np
x=np.array([[3,4],[3,5]])
print(x.flags)

which outputs the following:

  C_CONTIGUOUS : True
  F_CONTIGUOUS : False
  OWNDATA : True
  WRITEABLE : True
  ALIGNED : True
  UPDATEIFCOPY : False

1 Answer 1

1

It gives information about how the array is stored in memory.

C_CONTIGUOUS true means it is stored as c-type in memory.

See the documentation for more on each attribute.

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you, but I'm trying to figure out what kind of information. I understand OWNDATA and WRITABLE and starting to understand C_CONTIGUOUS and F_CONTIGUOUS as well (but not why in a higher dimensional array they can both be true).
@Femkemilene I guess it is because internally each dimension are stored separately. So on can be a c-type and the other a f-type.
I don't understand your answer. As far as I understand the arrays are always stored contiguous (so not seperately?), for C-contiguous the rows are stored next to each other, for F-contiguous the columns.. Would I be right to assume that the only way in which higher-dimensional arrays can be stored in the same way is that they only have one element in each dimension?
@Femkemilene you are right data is contiguous as detailed here docs.scipy.org/doc/numpy/reference/arrays.ndarray.html
@Femkemilene it seems that it is only possible if self.shape[k]=1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.