简体   繁体   中英

create ndarray from numpy memmap slice

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)

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

b.flags

attribute, which is False for a slice...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM