1

I am wondering how to determine if an object is a direct memmap object or a slice descendent of one.

The easiest way to as the question is with an example:

>>> import numpy as np
>>> filename = '../sandbox/test.bin'
>>> a = np.memmap(filename, dtype='float32', offset=0, shape=(4,2), order='F')
>>> print a
[[ 1.  5.]
 [ 2.  6.]
 [ 3.  7.]
 [ 4.  8.]]
>>> a.filename
'Z:\\CNI\\sandbox\\test.bin'
>>> a.shape
(4L, 2L)
>>> a.offset
0
>>>
>>> b = a[:,1]
>>> print b
[ 5.  6.  7.  8.]
>>> b.filename
'Z:\\CNI\\sandbox\\test.bin'
>>> b.shape
(4L,)
>>> b.offset
0
>>>

how would I determine that b is not a memmap object, but is instead a slice descendent of one? Or at the very least that b's offset is wrong. (in this example the offset should be 4)

4
  • Check out the function get_data_base from here. I'm not 1000% sure it works with memmaps, but a priori it should. Commented Nov 13, 2014 at 9:50
  • 1
    @user3701099 in this example you can check the OWNDATA parameter of the b.flags attribute, which is False for a slice... Commented Nov 13, 2014 at 14:31
  • @SaulloCastro the OWNDATA in flags attribute works and is very straightforward Commented Nov 13, 2014 at 17:39
  • @eickenberg the get_data_base function also works from the link you post Commented Nov 13, 2014 at 17:40

1 Answer 1

1

In this example you can check the OWNDATA parameter of the:

b.flags

attribute, which is False for a slice...

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

Comments

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.