/usr/share/doc/python-h5py-doc/html/quick.html is in python-h5py-doc 2.7.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Quick Start Guide — h5py 2.7.0 documentation</title>
<link rel="stylesheet" href="_static/classic.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '2.7.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="top" title="h5py 2.7.0 documentation" href="index.html" />
<link rel="next" title="Installation" href="build.html" />
<link rel="prev" title="HDF5 for Python" href="index.html" />
</head>
<body role="document">
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="build.html" title="Installation"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="index.html" title="HDF5 for Python"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">h5py 2.7.0 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="quick-start-guide">
<span id="quick"></span><h1>Quick Start Guide<a class="headerlink" href="#quick-start-guide" title="Permalink to this headline">¶</a></h1>
<div class="section" id="install">
<h2>Install<a class="headerlink" href="#install" title="Permalink to this headline">¶</a></h2>
<p>With <a class="reference external" href="http://continuum.io/downloads">Anaconda</a> or
<a class="reference external" href="http://conda.pydata.org/miniconda.html">Miniconda</a>:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">conda</span> <span class="n">install</span> <span class="n">h5py</span>
</pre></div>
</div>
<p>With <a class="reference external" href="https://www.enthought.com/products/canopy/">Enthought Canopy</a>, use
the GUI package manager or:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">enpkg</span> <span class="n">h5py</span>
</pre></div>
</div>
<p>With pip or setup.py, see <a class="reference internal" href="build.html#install"><span class="std std-ref">Installation</span></a>.</p>
</div>
<div class="section" id="core-concepts">
<h2>Core concepts<a class="headerlink" href="#core-concepts" title="Permalink to this headline">¶</a></h2>
<p>An HDF5 file is a container for two kinds of objects: <cite>datasets</cite>, which are
array-like collections of data, and <cite>groups</cite>, which are folder-like containers
that hold datasets and other groups. The most fundamental thing to remember
when using h5py is:</p>
<blockquote>
<div><strong>Groups work like dictionaries, and datasets work like NumPy arrays</strong></div></blockquote>
<p>The very first thing you’ll need to do is create a new file:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">h5py</span>
<span class="gp">>>> </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="go">>>></span>
<span class="gp">>>> </span><span class="n">f</span> <span class="o">=</span> <span class="n">h5py</span><span class="o">.</span><span class="n">File</span><span class="p">(</span><span class="s2">"mytestfile.hdf5"</span><span class="p">,</span> <span class="s2">"w"</span><span class="p">)</span>
</pre></div>
</div>
<p>The <a class="reference internal" href="high/file.html#file"><span class="std std-ref">File object</span></a> is your starting point. It has a couple of
methods which look interesting. One of them is <code class="docutils literal"><span class="pre">create_dataset</span></code>:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">dset</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">create_dataset</span><span class="p">(</span><span class="s2">"mydataset"</span><span class="p">,</span> <span class="p">(</span><span class="mi">100</span><span class="p">,),</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">'i'</span><span class="p">)</span>
</pre></div>
</div>
<p>The object we created isn’t an array, but <a class="reference internal" href="high/dataset.html#dataset"><span class="std std-ref">an HDF5 dataset</span></a>.
Like NumPy arrays, datasets have both a shape and a data type:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">dset</span><span class="o">.</span><span class="n">shape</span>
<span class="go">(100,)</span>
<span class="gp">>>> </span><span class="n">dset</span><span class="o">.</span><span class="n">dtype</span>
<span class="go">dtype('int32')</span>
</pre></div>
</div>
<p>They also support array-style slicing. This is how you read and write data
from a dataset in the file:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">dset</span><span class="p">[</span><span class="o">...</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">100</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">dset</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="go">0</span>
<span class="gp">>>> </span><span class="n">dset</span><span class="p">[</span><span class="mi">10</span><span class="p">]</span>
<span class="go">10</span>
<span class="gp">>>> </span><span class="n">dset</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">100</span><span class="p">:</span><span class="mi">10</span><span class="p">]</span>
<span class="go">array([ 0, 10, 20, 30, 40, 50, 60, 70, 80, 90])</span>
</pre></div>
</div>
<p>For more, see <a class="reference internal" href="high/file.html#file"><span class="std std-ref">File Objects</span></a> and <a class="reference internal" href="high/dataset.html#dataset"><span class="std std-ref">Datasets</span></a>.</p>
</div>
<div class="section" id="groups-and-hierarchical-organization">
<h2>Groups and hierarchical organization<a class="headerlink" href="#groups-and-hierarchical-organization" title="Permalink to this headline">¶</a></h2>
<p>“HDF” stands for “Hierarchical Data Format”. Every object in an HDF5 file
has a name, and they’re arranged in a POSIX-style hierarchy with
<code class="docutils literal"><span class="pre">/</span></code>-separators:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">dset</span><span class="o">.</span><span class="n">name</span>
<span class="go">u'/mydataset'</span>
</pre></div>
</div>
<p>The “folders” in this system are called <a class="reference internal" href="high/group.html#group"><span class="std std-ref">groups</span></a>. The <code class="docutils literal"><span class="pre">File</span></code> object we
created is itself a group, in this case the <cite>root group</cite>, named <code class="docutils literal"><span class="pre">/</span></code>:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">f</span><span class="o">.</span><span class="n">name</span>
<span class="go">u'/'</span>
</pre></div>
</div>
<p>Creating a subgroup is accomplished via the aptly-named <code class="docutils literal"><span class="pre">create_group</span></code>:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">grp</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">create_group</span><span class="p">(</span><span class="s2">"subgroup"</span><span class="p">)</span>
</pre></div>
</div>
<p>All <code class="docutils literal"><span class="pre">Group</span></code> objects also have the <code class="docutils literal"><span class="pre">create_*</span></code> methods like File:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">dset2</span> <span class="o">=</span> <span class="n">grp</span><span class="o">.</span><span class="n">create_dataset</span><span class="p">(</span><span class="s2">"another_dataset"</span><span class="p">,</span> <span class="p">(</span><span class="mi">50</span><span class="p">,),</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">'f'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">dset2</span><span class="o">.</span><span class="n">name</span>
<span class="go">u'/subgroup/another_dataset'</span>
</pre></div>
</div>
<p>By the way, you don’t have to create all the intermediate groups manually.
Specifying a full path works just fine:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">dset3</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">create_dataset</span><span class="p">(</span><span class="s1">'subgroup2/dataset_three'</span><span class="p">,</span> <span class="p">(</span><span class="mi">10</span><span class="p">,),</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">'i'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">dset3</span><span class="o">.</span><span class="n">name</span>
<span class="go">u'/subgroup2/dataset_three'</span>
</pre></div>
</div>
<p>Groups support most of the Python dictionary-style interface.
You retrieve objects in the file using the item-retrieval syntax:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">dataset_three</span> <span class="o">=</span> <span class="n">f</span><span class="p">[</span><span class="s1">'subgroup2/dataset_three'</span><span class="p">]</span>
</pre></div>
</div>
<p>Iterating over a group provides the names of its members:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">f</span><span class="p">:</span>
<span class="gp">... </span> <span class="nb">print</span> <span class="n">name</span>
<span class="go">mydataset</span>
<span class="go">subgroup</span>
<span class="go">subgroup2</span>
</pre></div>
</div>
<p>Containership testing also uses names:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="s2">"mydataset"</span> <span class="ow">in</span> <span class="n">f</span>
<span class="go">True</span>
<span class="gp">>>> </span><span class="s2">"somethingelse"</span> <span class="ow">in</span> <span class="n">f</span>
<span class="go">False</span>
</pre></div>
</div>
<p>You can even use full path names:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="s2">"subgroup/another_dataset"</span> <span class="ow">in</span> <span class="n">f</span>
<span class="go">True</span>
</pre></div>
</div>
<p>There are also the familiar <code class="docutils literal"><span class="pre">keys()</span></code>, <code class="docutils literal"><span class="pre">values()</span></code>, <code class="docutils literal"><span class="pre">items()</span></code> and
<code class="docutils literal"><span class="pre">iter()</span></code> methods, as well as <code class="docutils literal"><span class="pre">get()</span></code>.</p>
<p>Since iterating over a group only yields its directly-attached members,
iterating over an entire file is accomplished with the <code class="docutils literal"><span class="pre">Group</span></code> methods
<code class="docutils literal"><span class="pre">visit()</span></code> and <code class="docutils literal"><span class="pre">visititems()</span></code>, which take a callable:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">def</span> <span class="nf">printname</span><span class="p">(</span><span class="n">name</span><span class="p">):</span>
<span class="gp">... </span> <span class="nb">print</span> <span class="n">name</span>
<span class="gp">>>> </span><span class="n">f</span><span class="o">.</span><span class="n">visit</span><span class="p">(</span><span class="n">printname</span><span class="p">)</span>
<span class="go">mydataset</span>
<span class="go">subgroup</span>
<span class="go">subgroup/another_dataset</span>
<span class="go">subgroup2</span>
<span class="go">subgroup2/dataset_three</span>
</pre></div>
</div>
<p>For more, see <a class="reference internal" href="high/group.html#group"><span class="std std-ref">Groups</span></a>.</p>
</div>
<div class="section" id="attributes">
<h2>Attributes<a class="headerlink" href="#attributes" title="Permalink to this headline">¶</a></h2>
<p>One of the best features of HDF5 is that you can store metadata right next
to the data it describes. All groups and datasets support attached named
bits of data called <cite>attributes</cite>.</p>
<p>Attributes are accessed through the <code class="docutils literal"><span class="pre">attrs</span></code> proxy object, which again
implements the dictionary interface:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">dset</span><span class="o">.</span><span class="n">attrs</span><span class="p">[</span><span class="s1">'temperature'</span><span class="p">]</span> <span class="o">=</span> <span class="mf">99.5</span>
<span class="gp">>>> </span><span class="n">dset</span><span class="o">.</span><span class="n">attrs</span><span class="p">[</span><span class="s1">'temperature'</span><span class="p">]</span>
<span class="go">99.5</span>
<span class="gp">>>> </span><span class="s1">'temperature'</span> <span class="ow">in</span> <span class="n">dset</span><span class="o">.</span><span class="n">attrs</span>
<span class="go">True</span>
</pre></div>
</div>
<p>For more, see <a class="reference internal" href="high/attr.html#attributes"><span class="std std-ref">Attributes</span></a>.</p>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Quick Start Guide</a><ul>
<li><a class="reference internal" href="#install">Install</a></li>
<li><a class="reference internal" href="#core-concepts">Core concepts</a></li>
<li><a class="reference internal" href="#groups-and-hierarchical-organization">Groups and hierarchical organization</a></li>
<li><a class="reference internal" href="#attributes">Attributes</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="index.html"
title="previous chapter">HDF5 for Python</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="build.html"
title="next chapter">Installation</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/quick.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<div><input type="text" name="q" /></div>
<div><input type="submit" value="Go" /></div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="build.html" title="Installation"
>next</a> |</li>
<li class="right" >
<a href="index.html" title="HDF5 for Python"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">h5py 2.7.0 documentation</a> »</li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2017, Andrew Collette and contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.9.
</div>
</body>
</html>
|