Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The double-allocation you are seeing in your first example isn't due to memmap behaviour; rather, it is due to how <code>__getitem__</code> is implemented for numpy's ndarray class. When an ndarray is indexed using a list (as in your first example), data are copied from the source array. When it is indexed using a slice object, a view is created into the source array (no data are copied). For example:</p> <pre><code>In [2]: x = np.arange(16).reshape((4,4)) In [3]: x Out[3]: array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11], [12, 13, 14, 15]]) In [4]: y = x[[0, 2], :] In [5]: y[:, :] = 100 In [6]: x Out[6]: array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11], [12, 13, 14, 15]]) </code></pre> <p><code>y</code> is a copy of data from <code>x</code> so changing <code>y</code> had no effect on <code>x</code>. Now index the array via slicing:</p> <pre><code>In [7]: z = x[::2, :] In [8]: z[:, :] = 100 In [9]: x Out[9]: array([[100, 100, 100, 100], [ 4, 5, 6, 7], [100, 100, 100, 100], [ 12, 13, 14, 15]]) </code></pre> <p>Regarding your first question, I'm not aware of a method that will allow you to create <em>arbitrary</em> slices that include with entire array without reading the entire array into memory. Two options you might consider (in addition to something like HDF5/PyTables, which you already discussed):</p> <ol> <li><p>If you are accessing elements of you training &amp; test sets sequentially (rather than operating on them as two entire arrays), you could easily write a small wrapper class whose <code>__getitem__</code> method uses your index arrays to pull the appropriate sample from the memmap (i.e., training[i] returns big_mmap[training_ids[i]])</p></li> <li><p>Split your array into two separate files, which contain exclusively training or test values. Then you could use two separate memmap objects.</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload