-3

I have never used Python and I saw one piece of code from a manual and I would love to know what does it mean.

This is the code from the manual:

    import h5py
    h5file = h5py.File('Output/ScottCreek250b/simulation.results.DY.hdf5')
    channel_flows = h5file['Channel/Qc_out'][...]
    plt.plot(channel_flows[:, 0])
    plt.ylim((-0.01,0.01))
    plt.title('Streamflow at outlet', fontweight='bold')
    plt.ylabel('Flow ($\mathbf{m^3/s}$)')
    plt.xlabel('Model time-steps (24 hours)')

I would like to know what this two line mean, especially [...] and what are [:, 0] and [:, :10] stands for.

    channel_flows = h5file['Channel/Qc_out'][...]
    plt.plot(channel_flows[:, 0])

    soil_stores = h5file['Soil/V_s'][...]
    plt.plot(soil_stores[:, :10])
Yu Deng
  • 1,051
  • 4
  • 18
  • 35
  • That is `numpy` indexing - see http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html – jonrsharpe Jun 17 '14 at 12:56
  • Can i assume that the data structure is similar as a list objective like in R or like a 3D array? [...] would mean x, y, z values. – Yu Deng Jun 17 '14 at 13:06
  • 1
    I don't know R - read the documentation I have linked to, which explains how it works. – jonrsharpe Jun 17 '14 at 13:07

1 Answers1

3

The numpy documentation won't explain why the indices are used as they are, in particular the first ones on the h5file:

The [...] on the h5file lines are needed to actually copy the data; if not, a reference is passed, which may not always be what one wants. In this case, though, it looks like it's unnecessary and may have just been a force of habit.

After that, you're left with two dimensional data arrays (note: not 3D as you suggest), where the first dimension is indexed over the complete range (by use of the sole ':'), and the second inner dimension is indexed as a single value (0) or a range of the first ten values (:10, where the 0 in 0:10 is the default and can be omitted).