| <!DOCTYPE html> |
| |
| <html lang="en"> |
| <head> |
| <meta charset="utf-8"/> |
| <meta content="IE=edge" http-equiv="X-UA-Compatible"/> |
| <meta content="width=device-width, initial-scale=1" name="viewport"/> |
| <title>Sparse NDArray API — mxnet documentation</title> |
| <link crossorigin="anonymous" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" rel="stylesheet"/> |
| <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"/> |
| <link href="../../../_static/basic.css" rel="stylesheet" type="text/css"> |
| <link href="../../../_static/pygments.css" rel="stylesheet" type="text/css"> |
| <link href="../../../_static/mxnet.css" rel="stylesheet" type="text/css"/> |
| <script type="text/javascript"> |
| var DOCUMENTATION_OPTIONS = { |
| URL_ROOT: '../../../', |
| VERSION: '', |
| COLLAPSE_INDEX: false, |
| FILE_SUFFIX: '.html', |
| HAS_SOURCE: true, |
| SOURCELINK_SUFFIX: '' |
| }; |
| </script> |
| <script src="../../../_static/jquery-1.11.1.js" type="text/javascript"></script> |
| <script src="../../../_static/underscore.js" type="text/javascript"></script> |
| <script src="../../../_static/searchtools_custom.js" type="text/javascript"></script> |
| <script src="../../../_static/doctools.js" type="text/javascript"></script> |
| <script src="../../../_static/selectlang.js" type="text/javascript"></script> |
| <script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script> |
| <script type="text/javascript"> jQuery(function() { Search.loadIndex("/searchindex.js"); Search.init();}); </script> |
| <script> |
| (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ |
| (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new |
| Date();a=s.createElement(o), |
| m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) |
| })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); |
| |
| ga('create', 'UA-96378503-1', 'auto'); |
| ga('send', 'pageview'); |
| |
| </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> --> |
| <!-- --> |
| <!-- <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> --> |
| <!-- --> |
| <link href="../index.html" rel="up" title="MXNet - Python API"> |
| <link href="contrib.html" rel="next" title="Contrib NDArray API"/> |
| <link href="linalg.html" rel="prev" title="Linear Algebra NDArray API"/> |
| <link href="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/image/mxnet-icon.png" rel="icon" type="image/png"/> |
| </link></link></link></head> |
| <body background="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/image/mxnet-background.png" role="document"> |
| <div class="content-block"><div class="navbar navbar-fixed-top"> |
| <div class="container" id="navContainer"> |
| <div class="innder" id="header-inner"> |
| <h1 id="logo-wrap"> |
| <a href="../../../" id="logo"><img src="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/image/mxnet_logo.png"/></a> |
| </h1> |
| <nav class="nav-bar" id="main-nav"> |
| <a class="main-nav-link" href="../../../install/index.html">Install</a> |
| <a class="main-nav-link" href="../../../tutorials/index.html">Tutorials</a> |
| <span id="dropdown-menu-position-anchor"> |
| <a aria-expanded="true" aria-haspopup="true" class="main-nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button">Gluon <span class="caret"></span></a> |
| <ul class="dropdown-menu navbar-menu" id="package-dropdown-menu"> |
| <li><a class="main-nav-link" href="../../../gluon/index.html">About</a></li> |
| <li><a class="main-nav-link" href="http://gluon.mxnet.io">Tutorials</a></li> |
| </ul> |
| </span> |
| <span id="dropdown-menu-position-anchor"> |
| <a aria-expanded="true" aria-haspopup="true" class="main-nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button">API <span class="caret"></span></a> |
| <ul class="dropdown-menu navbar-menu" id="package-dropdown-menu"> |
| <li><a class="main-nav-link" href="../../../api/python/index.html">Python</a></li> |
| <li><a class="main-nav-link" href="../../../api/scala/index.html">Scala</a></li> |
| <li><a class="main-nav-link" href="../../../api/r/index.html">R</a></li> |
| <li><a class="main-nav-link" href="../../../api/julia/index.html">Julia</a></li> |
| <li><a class="main-nav-link" href="../../../api/c++/index.html">C++</a></li> |
| <li><a class="main-nav-link" href="../../../api/perl/index.html">Perl</a></li> |
| </ul> |
| </span> |
| <span id="dropdown-menu-position-anchor-docs"> |
| <a aria-expanded="true" aria-haspopup="true" class="main-nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button">Docs <span class="caret"></span></a> |
| <ul class="dropdown-menu navbar-menu" id="package-dropdown-menu-docs"> |
| <li><a class="main-nav-link" href="../../../faq/index.html">FAQ</a></li> |
| <li><a class="main-nav-link" href="../../../architecture/index.html">Architecture</a></li> |
| <li><a class="main-nav-link" href="https://github.com/apache/incubator-mxnet/tree/master/example">Examples</a></li> |
| <li><a class="main-nav-link" href="../../../model_zoo/index.html">Model Zoo</a></li> |
| </ul> |
| </span> |
| <a class="main-nav-link" href="https://github.com/dmlc/mxnet">Github</a> |
| <span id="dropdown-menu-position-anchor-community"> |
| <a aria-expanded="true" aria-haspopup="true" class="main-nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button">Community <span class="caret"></span></a> |
| <ul class="dropdown-menu navbar-menu" id="package-dropdown-menu-community"> |
| <li><a class="main-nav-link" href="../../../community/index.html">Community</a></li> |
| <li><a class="main-nav-link" href="../../../community/contribute.html">Contribute</a></li> |
| <li><a class="main-nav-link" href="../../../community/powered_by.html">Powered By</a></li> |
| </ul> |
| </span> |
| <a class="main-nav-link" href="http://discuss.mxnet.io">Discuss</a> |
| <span id="dropdown-menu-position-anchor-version" style="position: relative"><a href="#" class="main-nav-link dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="true">Versions(master)<span class="caret"></span></a><ul id="package-dropdown-menu" class="dropdown-menu"><li><a class="main-nav-link" href=https://mxnet.incubator.apache.org/>0.11.0</a></li><li><a class="main-nav-link" href=https://mxnet.incubator.apache.org/versions/0.11.0.rc3/index.html>0.11.0.rc3</a></li><li><a class="main-nav-link" href=https://mxnet.incubator.apache.org/versions/master/index.html>master</a></li></ul></span></nav> |
| <script> function getRootPath(){ return "../../../" } </script> |
| <div class="burgerIcon dropdown"> |
| <a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button">☰</a> |
| <ul class="dropdown-menu" id="burgerMenu"> |
| <li><a href="../../../install/index.html">Install</a></li> |
| <li><a class="main-nav-link" href="../../../tutorials/index.html">Tutorials</a></li> |
| <li class="dropdown-submenu"> |
| <a href="#" tabindex="-1">Community</a> |
| <ul class="dropdown-menu"> |
| <li><a href="../../../community/index.html" tabindex="-1">Community</a></li> |
| <li><a href="../../../community/contribute.html" tabindex="-1">Contribute</a></li> |
| <li><a href="../../../community/powered_by.html" tabindex="-1">Powered By</a></li> |
| </ul> |
| </li> |
| <li class="dropdown-submenu"> |
| <a href="#" tabindex="-1">API</a> |
| <ul class="dropdown-menu"> |
| <li><a href="../../../api/python/index.html" tabindex="-1">Python</a> |
| </li> |
| <li><a href="../../../api/scala/index.html" tabindex="-1">Scala</a> |
| </li> |
| <li><a href="../../../api/r/index.html" tabindex="-1">R</a> |
| </li> |
| <li><a href="../../../api/julia/index.html" tabindex="-1">Julia</a> |
| </li> |
| <li><a href="../../../api/c++/index.html" tabindex="-1">C++</a> |
| </li> |
| <li><a href="../../../api/perl/index.html" tabindex="-1">Perl</a> |
| </li> |
| </ul> |
| </li> |
| <li class="dropdown-submenu"> |
| <a href="#" tabindex="-1">Docs</a> |
| <ul class="dropdown-menu"> |
| <li><a href="../../../tutorials/index.html" tabindex="-1">Tutorials</a></li> |
| <li><a href="../../../faq/index.html" tabindex="-1">FAQ</a></li> |
| <li><a href="../../../architecture/index.html" tabindex="-1">Architecture</a></li> |
| <li><a href="https://github.com/apache/incubator-mxnet/tree/master/example" tabindex="-1">Examples</a></li> |
| <li><a href="../../../model_zoo/index.html" tabindex="-1">Model Zoo</a></li> |
| </ul> |
| </li> |
| <li><a href="../../../architecture/index.html">Architecture</a></li> |
| <li><a class="main-nav-link" href="https://github.com/dmlc/mxnet">Github</a></li> |
| <li id="dropdown-menu-position-anchor-version-mobile" class="dropdown-submenu" style="position: relative"><a href="#" tabindex="-1">Versions(master)</a><ul class="dropdown-menu"><li><a tabindex="-1" href=https://mxnet.incubator.apache.org/>0.11.0</a></li><li><a tabindex="-1" href=https://mxnet.incubator.apache.org/versions/0.11.0.rc3/index.html>0.11.0.rc3</a></li><li><a tabindex="-1" href=https://mxnet.incubator.apache.org/versions/master/index.html>master</a></li></ul></li></ul> |
| </div> |
| <div class="plusIcon dropdown"> |
| <a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button"><span aria-hidden="true" class="glyphicon glyphicon-plus"></span></a> |
| <ul class="dropdown-menu dropdown-menu-right" id="plusMenu"></ul> |
| </div> |
| <div id="search-input-wrap"> |
| <form action="../../../search.html" autocomplete="off" class="" method="get" role="search"> |
| <div class="form-group inner-addon left-addon"> |
| <i class="glyphicon glyphicon-search"></i> |
| <input class="form-control" name="q" placeholder="Search" type="text"/> |
| </div> |
| <input name="check_keywords" type="hidden" value="yes"> |
| <input name="area" type="hidden" value="default"/> |
| </input></form> |
| <div id="search-preview"></div> |
| </div> |
| <div id="searchIcon"> |
| <span aria-hidden="true" class="glyphicon glyphicon-search"></span> |
| </div> |
| <!-- <div id="lang-select-wrap"> --> |
| <!-- <label id="lang-select-label"> --> |
| <!-- <\!-- <i class="fa fa-globe"></i> -\-> --> |
| <!-- <span></span> --> |
| <!-- </label> --> |
| <!-- <select id="lang-select"> --> |
| <!-- <option value="en">Eng</option> --> |
| <!-- <option value="zh">中文</option> --> |
| <!-- </select> --> |
| <!-- </div> --> |
| <!-- <a id="mobile-nav-toggle"> |
| <span class="mobile-nav-toggle-bar"></span> |
| <span class="mobile-nav-toggle-bar"></span> |
| <span class="mobile-nav-toggle-bar"></span> |
| </a> --> |
| </div> |
| </div> |
| </div> |
| <script type="text/javascript"> |
| $('body').css('background', 'white'); |
| </script> |
| <div class="container"> |
| <div class="row"> |
| <div aria-label="main navigation" class="sphinxsidebar leftsidebar" role="navigation"> |
| <div class="sphinxsidebarwrapper"> |
| <ul class="current"> |
| <li class="toctree-l1 current"><a class="reference internal" href="../index.html">Python Documents</a><ul class="current"> |
| <li class="toctree-l2 current"><a class="reference internal" href="../index.html#ndarray-api">NDArray API</a><ul class="current"> |
| <li class="toctree-l3"><a class="reference internal" href="ndarray.html">NDArray API</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="random.html">Random Distribution Generator NDArray API</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="linalg.html">Linear Algebra NDArray API</a></li> |
| <li class="toctree-l3 current"><a class="current reference internal" href="">Sparse NDArray API</a><ul> |
| <li class="toctree-l4"><a class="reference internal" href="#overview">Overview</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="#the-csrndarray-class">The <code class="docutils literal"><span class="pre">CSRNDArray</span></code> class</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="#the-rowsparsendarray-class">The <code class="docutils literal"><span class="pre">RowSparseNDArray</span></code> class</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="#array-creation-routines">Array creation routines</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="#array-manipulation-routines">Array manipulation routines</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="#mathematical-functions">Mathematical functions</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="#api-reference">API Reference</a></li> |
| </ul> |
| </li> |
| <li class="toctree-l3"><a class="reference internal" href="contrib.html">Contrib NDArray API</a></li> |
| </ul> |
| </li> |
| <li class="toctree-l2"><a class="reference internal" href="../index.html#symbol-api">Symbol API</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../index.html#module-api">Module API</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../index.html#autograd-api">Autograd API</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../index.html#gluon-api">Gluon API</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../index.html#kvstore-api">KVStore API</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../index.html#io-api">IO API</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../index.html#image-api">Image API</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../index.html#optimization-api">Optimization API</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../index.html#callback-api">Callback API</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../index.html#metric-api">Metric API</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../index.html#run-time-compilation-api">Run-Time Compilation API</a></li> |
| </ul> |
| </li> |
| <li class="toctree-l1"><a class="reference internal" href="../../r/index.html">R Documents</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../julia/index.html">Julia Documents</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../c++/index.html">C++ Documents</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../scala/index.html">Scala Documents</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../perl/index.html">Perl Documents</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../faq/index.html">HowTo Documents</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../architecture/index.html">System Documents</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../tutorials/index.html">Tutorials</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../community/index.html">Community</a></li> |
| </ul> |
| </div> |
| </div> |
| <div class="content"> |
| <div class="page-tracker"></div> |
| <div class="section" id="sparse-ndarray-api"> |
| <span id="sparse-ndarray-api"></span><h1>Sparse NDArray API<a class="headerlink" href="#sparse-ndarray-api" title="Permalink to this headline">¶</a></h1> |
| <div class="section" id="overview"> |
| <span id="overview"></span><h2>Overview<a class="headerlink" href="#overview" title="Permalink to this headline">¶</a></h2> |
| <p>This document lists the routines of the <em>n</em>-dimensional sparse array package:</p> |
| <table border="1" class="longtable docutils"> |
| <colgroup> |
| <col width="10%"/> |
| <col width="90%"/> |
| </colgroup> |
| <tbody valign="top"> |
| <tr class="row-odd"><td><a class="reference internal" href="#module-mxnet.ndarray.sparse" title="mxnet.ndarray.sparse"><code class="xref py py-obj docutils literal"><span class="pre">mxnet.ndarray.sparse</span></code></a></td> |
| <td>Sparse NDArray API of MXNet.</td> |
| </tr> |
| </tbody> |
| </table> |
| <p>The <code class="docutils literal"><span class="pre">CSRNDArray</span></code> and <code class="docutils literal"><span class="pre">RowSparseNDArray</span></code> API, defined in the <code class="docutils literal"><span class="pre">ndarray.sparse</span></code> package, provides |
| imperative sparse tensor operations on <strong>CPU</strong>.</p> |
| <p>An <code class="docutils literal"><span class="pre">CSRNDArray</span></code> inherits from <code class="docutils literal"><span class="pre">NDArray</span></code>, and represents a two-dimensional, fixed-size array in compressed sparse row format.</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">]])</span> |
| <span class="gp">>>> </span><span class="n">csr</span> <span class="o">=</span> <span class="n">x</span><span class="o">.</span><span class="n">tostype</span><span class="p">(</span><span class="s1">'csr'</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="nb">type</span><span class="p">(</span><span class="n">csr</span><span class="p">)</span> |
| <span class="go"><class 'mxnet.ndarray.sparse.CSRNDArray'></span> |
| <span class="gp">>>> </span><span class="n">csr</span><span class="o">.</span><span class="n">shape</span> |
| <span class="go">(3, 2)</span> |
| <span class="gp">>>> </span><span class="n">csr</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">array([ 1. 2. 3.], dtype=float32)</span> |
| <span class="gp">>>> </span><span class="n">csr</span><span class="o">.</span><span class="n">indices</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">array([0, 0, 1])</span> |
| <span class="gp">>>> </span><span class="n">csr</span><span class="o">.</span><span class="n">indptr</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">array([0, 1, 1, 3])</span> |
| <span class="gp">>>> </span><span class="n">csr</span><span class="o">.</span><span class="n">stype</span> |
| <span class="go">'csr'</span> |
| </pre></div> |
| </div> |
| <p>A detailed tutorial is available at |
| <a class="reference external" href="https:https://mxnet.incubator.apache.org/versions/master/tutorials/sparse/csr.html">CSRNDArray - NDArray in Compressed Sparse Row Storage Format</a>. |
| <br/></p> |
| <p>An <code class="docutils literal"><span class="pre">RowSparseNDArray</span></code> inherits from <code class="docutils literal"><span class="pre">NDArray</span></code>, and represents a multi-dimensional, fixed-size array in row sparse format.</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">]])</span> |
| <span class="gp">>>> </span><span class="n">row_sparse</span> <span class="o">=</span> <span class="n">x</span><span class="o">.</span><span class="n">tostype</span><span class="p">(</span><span class="s1">'row_sparse'</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="nb">type</span><span class="p">(</span><span class="n">row_sparse</span><span class="p">)</span> |
| <span class="go"><class 'mxnet.ndarray.sparse.RowSparseNDArray'></span> |
| <span class="gp">>>> </span><span class="n">row_sparse</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">array([[ 1. 0.],</span> |
| <span class="go"> [ 2. 3.]], dtype=float32)</span> |
| <span class="gp">>>> </span><span class="n">row_sparse</span><span class="o">.</span><span class="n">indices</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">array([0, 2])</span> |
| <span class="gp">>>> </span><span class="n">row_sparse</span><span class="o">.</span><span class="n">stype</span> |
| <span class="go">'row_sparse'</span> |
| </pre></div> |
| </div> |
| <p>A detailed tutorial is available at |
| <a class="reference external" href="https://mxnet.incubator.apache.org/versions/master/tutorials/sparse/row_sparse.html">RowSparseNDArray - NDArray for Sparse Gradient Updates</a>. |
| <br/><br/></p> |
| <div class="admonition note"> |
| <p class="first admonition-title">Note</p> |
| <p><code class="docutils literal"><span class="pre">mxnet.ndarray.sparse</span></code> is similar to <code class="docutils literal"><span class="pre">mxnet.ndarray</span></code> in some aspects. But the differences are not negligible. For instance:</p> |
| <ul class="last simple"> |
| <li>Only a subset of operators in <code class="docutils literal"><span class="pre">mxnet.ndarray</span></code> have specialized implementations in <code class="docutils literal"><span class="pre">mxnet.ndarray.sparse</span></code>. |
| Operators such as Convolution and broadcasting do not have sparse implementations yet.</li> |
| <li>The storage types (<code class="docutils literal"><span class="pre">stype</span></code>) of sparse operators’ outputs depend on the storage types of inputs. |
| By default the operators not available in <code class="docutils literal"><span class="pre">mxnet.ndarray.sparse</span></code> infer “default” (dense) storage type for outputs. |
| Please refer to the [API Reference](#api-reference) section for further details on specific operators.</li> |
| <li>GPU support for <code class="docutils literal"><span class="pre">mxnet.ndarray.sparse</span></code> is experimental. Only a few sparse operators are supported on GPU such as <code class="docutils literal"><span class="pre">sparse.dot</span></code>.</li> |
| </ul> |
| </div> |
| <div class="admonition note"> |
| <p class="first admonition-title">Note</p> |
| <p><code class="docutils literal"><span class="pre">mxnet.ndarray.sparse.CSRNDArray</span></code> is similar to <code class="docutils literal"><span class="pre">scipy.sparse.csr_matrix</span></code> in some aspects. But they differ in a few aspects:</p> |
| <ul class="last simple"> |
| <li>In MXNet the column indices (<code class="docutils literal"><span class="pre">CSRNDArray.indices</span></code>) for a given row are expected to be <strong>sorted in ascending order</strong>. |
| Duplicate column entries for the same row are not allowed.</li> |
| <li><code class="docutils literal"><span class="pre">CSRNDArray.data</span></code>, <code class="docutils literal"><span class="pre">CSRNDArray.indices</span></code> and <code class="docutils literal"><span class="pre">CSRNDArray.indptr</span></code> always create deep copies, while it’s not the case in <code class="docutils literal"><span class="pre">scipy.sparse.csr_matrix</span></code>.</li> |
| </ul> |
| </div> |
| <p>In the rest of this document, we first overview the methods provided by the |
| <code class="docutils literal"><span class="pre">ndarray.sparse.CSRNDArray</span></code> class and the <code class="docutils literal"><span class="pre">ndarray.sparse.RowSparseNDArray</span></code> class, |
| and then list other routines provided by the <code class="docutils literal"><span class="pre">ndarray.sparse</span></code> package.</p> |
| <p>The <code class="docutils literal"><span class="pre">ndarray.sparse</span></code> package provides several classes:</p> |
| <table border="1" class="longtable docutils"> |
| <colgroup> |
| <col width="10%"/> |
| <col width="90%"/> |
| </colgroup> |
| <tbody valign="top"> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.CSRNDArray" title="mxnet.ndarray.sparse.CSRNDArray"><code class="xref py py-obj docutils literal"><span class="pre">CSRNDArray</span></code></a></td> |
| <td>A sparse representation of 2D NDArray in the Compressed Sparse Row format.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.RowSparseNDArray" title="mxnet.ndarray.sparse.RowSparseNDArray"><code class="xref py py-obj docutils literal"><span class="pre">RowSparseNDArray</span></code></a></td> |
| <td>A sparse representation of a set of NDArray row slices at given indices.</td> |
| </tr> |
| </tbody> |
| </table> |
| <p>We summarize the interface for each class in the following sections.</p> |
| </div> |
| <div class="section" id="the-csrndarray-class"> |
| <span id="the-csrndarray-class"></span><h2>The <code class="docutils literal"><span class="pre">CSRNDArray</span></code> class<a class="headerlink" href="#the-csrndarray-class" title="Permalink to this headline">¶</a></h2> |
| <div class="section" id="array-attributes"> |
| <span id="array-attributes"></span><h3>Array attributes<a class="headerlink" href="#array-attributes" title="Permalink to this headline">¶</a></h3> |
| <table border="1" class="longtable docutils"> |
| <colgroup> |
| <col width="10%"/> |
| <col width="90%"/> |
| </colgroup> |
| <tbody valign="top"> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.CSRNDArray.shape" title="mxnet.ndarray.sparse.CSRNDArray.shape"><code class="xref py py-obj docutils literal"><span class="pre">CSRNDArray.shape</span></code></a></td> |
| <td>Tuple of array dimensions.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.CSRNDArray.context" title="mxnet.ndarray.sparse.CSRNDArray.context"><code class="xref py py-obj docutils literal"><span class="pre">CSRNDArray.context</span></code></a></td> |
| <td>Device context of the array.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.CSRNDArray.dtype" title="mxnet.ndarray.sparse.CSRNDArray.dtype"><code class="xref py py-obj docutils literal"><span class="pre">CSRNDArray.dtype</span></code></a></td> |
| <td>Data-type of the array’s elements.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.CSRNDArray.stype" title="mxnet.ndarray.sparse.CSRNDArray.stype"><code class="xref py py-obj docutils literal"><span class="pre">CSRNDArray.stype</span></code></a></td> |
| <td>Storage-type of the array.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.CSRNDArray.data" title="mxnet.ndarray.sparse.CSRNDArray.data"><code class="xref py py-obj docutils literal"><span class="pre">CSRNDArray.data</span></code></a></td> |
| <td>A deep copy NDArray of the data array of the CSRNDArray.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.CSRNDArray.indices" title="mxnet.ndarray.sparse.CSRNDArray.indices"><code class="xref py py-obj docutils literal"><span class="pre">CSRNDArray.indices</span></code></a></td> |
| <td>A deep copy NDArray of the indices array of the CSRNDArray.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.CSRNDArray.indptr" title="mxnet.ndarray.sparse.CSRNDArray.indptr"><code class="xref py py-obj docutils literal"><span class="pre">CSRNDArray.indptr</span></code></a></td> |
| <td>A deep copy NDArray of the indptr array of the CSRNDArray.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="section" id="array-conversion"> |
| <span id="array-conversion"></span><h3>Array conversion<a class="headerlink" href="#array-conversion" title="Permalink to this headline">¶</a></h3> |
| <table border="1" class="longtable docutils"> |
| <colgroup> |
| <col width="10%"/> |
| <col width="90%"/> |
| </colgroup> |
| <tbody valign="top"> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.CSRNDArray.copy" title="mxnet.ndarray.sparse.CSRNDArray.copy"><code class="xref py py-obj docutils literal"><span class="pre">CSRNDArray.copy</span></code></a></td> |
| <td>Makes a copy of this <code class="docutils literal"><span class="pre">NDArray</span></code>, keeping the same context.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.CSRNDArray.copyto" title="mxnet.ndarray.sparse.CSRNDArray.copyto"><code class="xref py py-obj docutils literal"><span class="pre">CSRNDArray.copyto</span></code></a></td> |
| <td>Copies the value of this array to another array.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.CSRNDArray.as_in_context" title="mxnet.ndarray.sparse.CSRNDArray.as_in_context"><code class="xref py py-obj docutils literal"><span class="pre">CSRNDArray.as_in_context</span></code></a></td> |
| <td>Returns an array on the target device with the same value as this array.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.CSRNDArray.asnumpy" title="mxnet.ndarray.sparse.CSRNDArray.asnumpy"><code class="xref py py-obj docutils literal"><span class="pre">CSRNDArray.asnumpy</span></code></a></td> |
| <td>Return a dense <code class="docutils literal"><span class="pre">numpy.ndarray</span></code> object with value copied from this array</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.CSRNDArray.asscalar" title="mxnet.ndarray.sparse.CSRNDArray.asscalar"><code class="xref py py-obj docutils literal"><span class="pre">CSRNDArray.asscalar</span></code></a></td> |
| <td>Returns a scalar whose value is copied from this array.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.CSRNDArray.astype" title="mxnet.ndarray.sparse.CSRNDArray.astype"><code class="xref py py-obj docutils literal"><span class="pre">CSRNDArray.astype</span></code></a></td> |
| <td>Returns a copy of the array after casting to a specified type.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.CSRNDArray.tostype" title="mxnet.ndarray.sparse.CSRNDArray.tostype"><code class="xref py py-obj docutils literal"><span class="pre">CSRNDArray.tostype</span></code></a></td> |
| <td>Return a copy of the array with chosen storage type.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="section" id="array-creation"> |
| <span id="array-creation"></span><h3>Array creation<a class="headerlink" href="#array-creation" title="Permalink to this headline">¶</a></h3> |
| <table border="1" class="longtable docutils"> |
| <colgroup> |
| <col width="10%"/> |
| <col width="90%"/> |
| </colgroup> |
| <tbody valign="top"> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.CSRNDArray.zeros_like" title="mxnet.ndarray.sparse.CSRNDArray.zeros_like"><code class="xref py py-obj docutils literal"><span class="pre">CSRNDArray.zeros_like</span></code></a></td> |
| <td>Convenience fluent method for <a class="reference internal" href="#mxnet.ndarray.sparse.zeros_like" title="mxnet.ndarray.sparse.zeros_like"><code class="xref py py-func docutils literal"><span class="pre">zeros_like()</span></code></a>.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="section" id="indexing"> |
| <span id="indexing"></span><h3>Indexing<a class="headerlink" href="#indexing" title="Permalink to this headline">¶</a></h3> |
| <table border="1" class="longtable docutils"> |
| <colgroup> |
| <col width="10%"/> |
| <col width="90%"/> |
| </colgroup> |
| <tbody valign="top"> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.CSRNDArray.__getitem__" title="mxnet.ndarray.sparse.CSRNDArray.__getitem__"><code class="xref py py-obj docutils literal"><span class="pre">CSRNDArray.__getitem__</span></code></a></td> |
| <td>x.__getitem__(i) <=> x[i]</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.CSRNDArray.__setitem__" title="mxnet.ndarray.sparse.CSRNDArray.__setitem__"><code class="xref py py-obj docutils literal"><span class="pre">CSRNDArray.__setitem__</span></code></a></td> |
| <td>x.__setitem__(i, y) <=> x[i]=y</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.CSRNDArray.slice" title="mxnet.ndarray.sparse.CSRNDArray.slice"><code class="xref py py-obj docutils literal"><span class="pre">CSRNDArray.slice</span></code></a></td> |
| <td>Convenience fluent method for <a class="reference internal" href="#mxnet.ndarray.sparse.slice" title="mxnet.ndarray.sparse.slice"><code class="xref py py-func docutils literal"><span class="pre">slice()</span></code></a>.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="section" id="lazy-evaluation"> |
| <span id="lazy-evaluation"></span><h3>Lazy evaluation<a class="headerlink" href="#lazy-evaluation" title="Permalink to this headline">¶</a></h3> |
| <table border="1" class="longtable docutils"> |
| <colgroup> |
| <col width="10%"/> |
| <col width="90%"/> |
| </colgroup> |
| <tbody valign="top"> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.CSRNDArray.wait_to_read" title="mxnet.ndarray.sparse.CSRNDArray.wait_to_read"><code class="xref py py-obj docutils literal"><span class="pre">CSRNDArray.wait_to_read</span></code></a></td> |
| <td>Waits until all previous write operations on the current array are finished.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| </div> |
| <div class="section" id="the-rowsparsendarray-class"> |
| <span id="the-rowsparsendarray-class"></span><h2>The <code class="docutils literal"><span class="pre">RowSparseNDArray</span></code> class<a class="headerlink" href="#the-rowsparsendarray-class" title="Permalink to this headline">¶</a></h2> |
| <div class="section" id="array-attributes"> |
| <span id="id1"></span><h3>Array attributes<a class="headerlink" href="#array-attributes" title="Permalink to this headline">¶</a></h3> |
| <table border="1" class="longtable docutils"> |
| <colgroup> |
| <col width="10%"/> |
| <col width="90%"/> |
| </colgroup> |
| <tbody valign="top"> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.RowSparseNDArray.shape" title="mxnet.ndarray.sparse.RowSparseNDArray.shape"><code class="xref py py-obj docutils literal"><span class="pre">RowSparseNDArray.shape</span></code></a></td> |
| <td>Tuple of array dimensions.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.RowSparseNDArray.context" title="mxnet.ndarray.sparse.RowSparseNDArray.context"><code class="xref py py-obj docutils literal"><span class="pre">RowSparseNDArray.context</span></code></a></td> |
| <td>Device context of the array.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.RowSparseNDArray.dtype" title="mxnet.ndarray.sparse.RowSparseNDArray.dtype"><code class="xref py py-obj docutils literal"><span class="pre">RowSparseNDArray.dtype</span></code></a></td> |
| <td>Data-type of the array’s elements.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.RowSparseNDArray.stype" title="mxnet.ndarray.sparse.RowSparseNDArray.stype"><code class="xref py py-obj docutils literal"><span class="pre">RowSparseNDArray.stype</span></code></a></td> |
| <td>Storage-type of the array.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.RowSparseNDArray.data" title="mxnet.ndarray.sparse.RowSparseNDArray.data"><code class="xref py py-obj docutils literal"><span class="pre">RowSparseNDArray.data</span></code></a></td> |
| <td>A deep copy NDArray of the data array of the RowSparseNDArray.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.RowSparseNDArray.indices" title="mxnet.ndarray.sparse.RowSparseNDArray.indices"><code class="xref py py-obj docutils literal"><span class="pre">RowSparseNDArray.indices</span></code></a></td> |
| <td>A deep copy NDArray of the indices array of the RowSparseNDArray.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="section" id="array-conversion"> |
| <span id="id2"></span><h3>Array conversion<a class="headerlink" href="#array-conversion" title="Permalink to this headline">¶</a></h3> |
| <table border="1" class="longtable docutils"> |
| <colgroup> |
| <col width="10%"/> |
| <col width="90%"/> |
| </colgroup> |
| <tbody valign="top"> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.RowSparseNDArray.copy" title="mxnet.ndarray.sparse.RowSparseNDArray.copy"><code class="xref py py-obj docutils literal"><span class="pre">RowSparseNDArray.copy</span></code></a></td> |
| <td>Makes a copy of this <code class="docutils literal"><span class="pre">NDArray</span></code>, keeping the same context.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.RowSparseNDArray.copyto" title="mxnet.ndarray.sparse.RowSparseNDArray.copyto"><code class="xref py py-obj docutils literal"><span class="pre">RowSparseNDArray.copyto</span></code></a></td> |
| <td>Copies the value of this array to another array.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.RowSparseNDArray.as_in_context" title="mxnet.ndarray.sparse.RowSparseNDArray.as_in_context"><code class="xref py py-obj docutils literal"><span class="pre">RowSparseNDArray.as_in_context</span></code></a></td> |
| <td>Returns an array on the target device with the same value as this array.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.RowSparseNDArray.asnumpy" title="mxnet.ndarray.sparse.RowSparseNDArray.asnumpy"><code class="xref py py-obj docutils literal"><span class="pre">RowSparseNDArray.asnumpy</span></code></a></td> |
| <td>Return a dense <code class="docutils literal"><span class="pre">numpy.ndarray</span></code> object with value copied from this array</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.RowSparseNDArray.asscalar" title="mxnet.ndarray.sparse.RowSparseNDArray.asscalar"><code class="xref py py-obj docutils literal"><span class="pre">RowSparseNDArray.asscalar</span></code></a></td> |
| <td>Returns a scalar whose value is copied from this array.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.RowSparseNDArray.astype" title="mxnet.ndarray.sparse.RowSparseNDArray.astype"><code class="xref py py-obj docutils literal"><span class="pre">RowSparseNDArray.astype</span></code></a></td> |
| <td>Returns a copy of the array after casting to a specified type.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.RowSparseNDArray.tostype" title="mxnet.ndarray.sparse.RowSparseNDArray.tostype"><code class="xref py py-obj docutils literal"><span class="pre">RowSparseNDArray.tostype</span></code></a></td> |
| <td>Return a copy of the array with chosen storage type.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="section" id="array-creation"> |
| <span id="id3"></span><h3>Array creation<a class="headerlink" href="#array-creation" title="Permalink to this headline">¶</a></h3> |
| <table border="1" class="longtable docutils"> |
| <colgroup> |
| <col width="10%"/> |
| <col width="90%"/> |
| </colgroup> |
| <tbody valign="top"> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.RowSparseNDArray.zeros_like" title="mxnet.ndarray.sparse.RowSparseNDArray.zeros_like"><code class="xref py py-obj docutils literal"><span class="pre">RowSparseNDArray.zeros_like</span></code></a></td> |
| <td>Convenience fluent method for <a class="reference internal" href="#mxnet.ndarray.sparse.zeros_like" title="mxnet.ndarray.sparse.zeros_like"><code class="xref py py-func docutils literal"><span class="pre">zeros_like()</span></code></a>.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="section" id="array-rounding"> |
| <span id="array-rounding"></span><h3>Array rounding<a class="headerlink" href="#array-rounding" title="Permalink to this headline">¶</a></h3> |
| <table border="1" class="longtable docutils"> |
| <colgroup> |
| <col width="10%"/> |
| <col width="90%"/> |
| </colgroup> |
| <tbody valign="top"> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.RowSparseNDArray.round" title="mxnet.ndarray.sparse.RowSparseNDArray.round"><code class="xref py py-obj docutils literal"><span class="pre">RowSparseNDArray.round</span></code></a></td> |
| <td>Convenience fluent method for <a class="reference internal" href="#mxnet.ndarray.sparse.round" title="mxnet.ndarray.sparse.round"><code class="xref py py-func docutils literal"><span class="pre">round()</span></code></a>.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.RowSparseNDArray.rint" title="mxnet.ndarray.sparse.RowSparseNDArray.rint"><code class="xref py py-obj docutils literal"><span class="pre">RowSparseNDArray.rint</span></code></a></td> |
| <td>Convenience fluent method for <a class="reference internal" href="#mxnet.ndarray.sparse.rint" title="mxnet.ndarray.sparse.rint"><code class="xref py py-func docutils literal"><span class="pre">rint()</span></code></a>.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.RowSparseNDArray.fix" title="mxnet.ndarray.sparse.RowSparseNDArray.fix"><code class="xref py py-obj docutils literal"><span class="pre">RowSparseNDArray.fix</span></code></a></td> |
| <td>Convenience fluent method for <a class="reference internal" href="#mxnet.ndarray.sparse.fix" title="mxnet.ndarray.sparse.fix"><code class="xref py py-func docutils literal"><span class="pre">fix()</span></code></a>.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.RowSparseNDArray.floor" title="mxnet.ndarray.sparse.RowSparseNDArray.floor"><code class="xref py py-obj docutils literal"><span class="pre">RowSparseNDArray.floor</span></code></a></td> |
| <td>Convenience fluent method for <a class="reference internal" href="#mxnet.ndarray.sparse.floor" title="mxnet.ndarray.sparse.floor"><code class="xref py py-func docutils literal"><span class="pre">floor()</span></code></a>.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.RowSparseNDArray.ceil" title="mxnet.ndarray.sparse.RowSparseNDArray.ceil"><code class="xref py py-obj docutils literal"><span class="pre">RowSparseNDArray.ceil</span></code></a></td> |
| <td>Convenience fluent method for <a class="reference internal" href="#mxnet.ndarray.sparse.ceil" title="mxnet.ndarray.sparse.ceil"><code class="xref py py-func docutils literal"><span class="pre">ceil()</span></code></a>.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.RowSparseNDArray.trunc" title="mxnet.ndarray.sparse.RowSparseNDArray.trunc"><code class="xref py py-obj docutils literal"><span class="pre">RowSparseNDArray.trunc</span></code></a></td> |
| <td>Convenience fluent method for <a class="reference internal" href="#mxnet.ndarray.sparse.trunc" title="mxnet.ndarray.sparse.trunc"><code class="xref py py-func docutils literal"><span class="pre">trunc()</span></code></a>.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="section" id="indexing"> |
| <span id="id4"></span><h3>Indexing<a class="headerlink" href="#indexing" title="Permalink to this headline">¶</a></h3> |
| <table border="1" class="longtable docutils"> |
| <colgroup> |
| <col width="10%"/> |
| <col width="90%"/> |
| </colgroup> |
| <tbody valign="top"> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.RowSparseNDArray.__getitem__" title="mxnet.ndarray.sparse.RowSparseNDArray.__getitem__"><code class="xref py py-obj docutils literal"><span class="pre">RowSparseNDArray.__getitem__</span></code></a></td> |
| <td>x.__getitem__(i) <=> x[i]</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.RowSparseNDArray.__setitem__" title="mxnet.ndarray.sparse.RowSparseNDArray.__setitem__"><code class="xref py py-obj docutils literal"><span class="pre">RowSparseNDArray.__setitem__</span></code></a></td> |
| <td>x.__setitem__(i, y) <=> x[i]=y</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="section" id="lazy-evaluation"> |
| <span id="id5"></span><h3>Lazy evaluation<a class="headerlink" href="#lazy-evaluation" title="Permalink to this headline">¶</a></h3> |
| <table border="1" class="longtable docutils"> |
| <colgroup> |
| <col width="10%"/> |
| <col width="90%"/> |
| </colgroup> |
| <tbody valign="top"> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.RowSparseNDArray.wait_to_read" title="mxnet.ndarray.sparse.RowSparseNDArray.wait_to_read"><code class="xref py py-obj docutils literal"><span class="pre">RowSparseNDArray.wait_to_read</span></code></a></td> |
| <td>Waits until all previous write operations on the current array are finished.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| </div> |
| <div class="section" id="array-creation-routines"> |
| <span id="array-creation-routines"></span><h2>Array creation routines<a class="headerlink" href="#array-creation-routines" title="Permalink to this headline">¶</a></h2> |
| <table border="1" class="longtable docutils"> |
| <colgroup> |
| <col width="10%"/> |
| <col width="90%"/> |
| </colgroup> |
| <tbody valign="top"> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.array" title="mxnet.ndarray.sparse.array"><code class="xref py py-obj docutils literal"><span class="pre">array</span></code></a></td> |
| <td>Creates a sparse array from any object exposing the array interface.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.empty" title="mxnet.ndarray.sparse.empty"><code class="xref py py-obj docutils literal"><span class="pre">empty</span></code></a></td> |
| <td>Returns a new array of given shape and type, without initializing entries.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.zeros" title="mxnet.ndarray.sparse.zeros"><code class="xref py py-obj docutils literal"><span class="pre">zeros</span></code></a></td> |
| <td>Return a new array of given shape and type, filled with zeros.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.zeros_like" title="mxnet.ndarray.sparse.zeros_like"><code class="xref py py-obj docutils literal"><span class="pre">zeros_like</span></code></a></td> |
| <td>Return an array of zeros with the same shape and type as the input array.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.csr_matrix" title="mxnet.ndarray.sparse.csr_matrix"><code class="xref py py-obj docutils literal"><span class="pre">csr_matrix</span></code></a></td> |
| <td>Creates a <cite>CSRNDArray</cite>, an 2D array with compressed sparse row (CSR) format.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.row_sparse_array" title="mxnet.ndarray.sparse.row_sparse_array"><code class="xref py py-obj docutils literal"><span class="pre">row_sparse_array</span></code></a></td> |
| <td>Creates a <cite>RowSparseNDArray</cite>, a multidimensional row sparse array with a set of tensor slices at given indices.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.load" title="mxnet.ndarray.load"><code class="xref py py-obj docutils literal"><span class="pre">mxnet.ndarray.load</span></code></a></td> |
| <td>Loads an array from file.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.save" title="mxnet.ndarray.save"><code class="xref py py-obj docutils literal"><span class="pre">mxnet.ndarray.save</span></code></a></td> |
| <td>Saves a list of arrays or a dict of str->array to file.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="section" id="array-manipulation-routines"> |
| <span id="array-manipulation-routines"></span><h2>Array manipulation routines<a class="headerlink" href="#array-manipulation-routines" title="Permalink to this headline">¶</a></h2> |
| <div class="section" id="changing-array-storage-type"> |
| <span id="changing-array-storage-type"></span><h3>Changing array storage type<a class="headerlink" href="#changing-array-storage-type" title="Permalink to this headline">¶</a></h3> |
| <table border="1" class="longtable docutils"> |
| <colgroup> |
| <col width="10%"/> |
| <col width="90%"/> |
| </colgroup> |
| <tbody valign="top"> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.cast_storage" title="mxnet.ndarray.sparse.cast_storage"><code class="xref py py-obj docutils literal"><span class="pre">cast_storage</span></code></a></td> |
| <td>Casts tensor storage type to the new type.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="section" id="indexing-routines"> |
| <span id="indexing-routines"></span><h3>Indexing routines<a class="headerlink" href="#indexing-routines" title="Permalink to this headline">¶</a></h3> |
| <table border="1" class="longtable docutils"> |
| <colgroup> |
| <col width="10%"/> |
| <col width="90%"/> |
| </colgroup> |
| <tbody valign="top"> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.slice" title="mxnet.ndarray.sparse.slice"><code class="xref py py-obj docutils literal"><span class="pre">slice</span></code></a></td> |
| <td>Slices a contiguous region of the array.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.retain" title="mxnet.ndarray.sparse.retain"><code class="xref py py-obj docutils literal"><span class="pre">retain</span></code></a></td> |
| <td>pick rows specified by user input index array from a row sparse matrix</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| </div> |
| <div class="section" id="mathematical-functions"> |
| <span id="mathematical-functions"></span><h2>Mathematical functions<a class="headerlink" href="#mathematical-functions" title="Permalink to this headline">¶</a></h2> |
| <div class="section" id="arithmetic-operations"> |
| <span id="arithmetic-operations"></span><h3>Arithmetic operations<a class="headerlink" href="#arithmetic-operations" title="Permalink to this headline">¶</a></h3> |
| <table border="1" class="longtable docutils"> |
| <colgroup> |
| <col width="10%"/> |
| <col width="90%"/> |
| </colgroup> |
| <tbody valign="top"> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.elemwise_add" title="mxnet.ndarray.sparse.elemwise_add"><code class="xref py py-obj docutils literal"><span class="pre">elemwise_add</span></code></a></td> |
| <td>Adds arguments element-wise.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.elemwise_sub" title="mxnet.ndarray.sparse.elemwise_sub"><code class="xref py py-obj docutils literal"><span class="pre">elemwise_sub</span></code></a></td> |
| <td>Subtracts arguments element-wise.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.elemwise_mul" title="mxnet.ndarray.sparse.elemwise_mul"><code class="xref py py-obj docutils literal"><span class="pre">elemwise_mul</span></code></a></td> |
| <td>Multiplies arguments element-wise.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.negative" title="mxnet.ndarray.sparse.negative"><code class="xref py py-obj docutils literal"><span class="pre">negative</span></code></a></td> |
| <td>Numerical negative of the argument, element-wise.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.dot" title="mxnet.ndarray.sparse.dot"><code class="xref py py-obj docutils literal"><span class="pre">dot</span></code></a></td> |
| <td>Dot product of two arrays.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.add_n" title="mxnet.ndarray.sparse.add_n"><code class="xref py py-obj docutils literal"><span class="pre">add_n</span></code></a></td> |
| <td>Adds all input arguments element-wise.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="section" id="trigonometric-functions"> |
| <span id="trigonometric-functions"></span><h3>Trigonometric functions<a class="headerlink" href="#trigonometric-functions" title="Permalink to this headline">¶</a></h3> |
| <table border="1" class="longtable docutils"> |
| <colgroup> |
| <col width="10%"/> |
| <col width="90%"/> |
| </colgroup> |
| <tbody valign="top"> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.sin" title="mxnet.ndarray.sparse.sin"><code class="xref py py-obj docutils literal"><span class="pre">sin</span></code></a></td> |
| <td>Computes the element-wise sine of the input array.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.tan" title="mxnet.ndarray.sparse.tan"><code class="xref py py-obj docutils literal"><span class="pre">tan</span></code></a></td> |
| <td>Computes the element-wise tangent of the input array.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.arcsin" title="mxnet.ndarray.sparse.arcsin"><code class="xref py py-obj docutils literal"><span class="pre">arcsin</span></code></a></td> |
| <td>Returns element-wise inverse sine of the input array.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.arctan" title="mxnet.ndarray.sparse.arctan"><code class="xref py py-obj docutils literal"><span class="pre">arctan</span></code></a></td> |
| <td>Returns element-wise inverse tangent of the input array.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.degrees" title="mxnet.ndarray.sparse.degrees"><code class="xref py py-obj docutils literal"><span class="pre">degrees</span></code></a></td> |
| <td>Converts each element of the input array from radians to degrees.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.radians" title="mxnet.ndarray.sparse.radians"><code class="xref py py-obj docutils literal"><span class="pre">radians</span></code></a></td> |
| <td>Converts each element of the input array from degrees to radians.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="section" id="hyperbolic-functions"> |
| <span id="hyperbolic-functions"></span><h3>Hyperbolic functions<a class="headerlink" href="#hyperbolic-functions" title="Permalink to this headline">¶</a></h3> |
| <table border="1" class="longtable docutils"> |
| <colgroup> |
| <col width="10%"/> |
| <col width="90%"/> |
| </colgroup> |
| <tbody valign="top"> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.sinh" title="mxnet.ndarray.sparse.sinh"><code class="xref py py-obj docutils literal"><span class="pre">sinh</span></code></a></td> |
| <td>Returns the hyperbolic sine of the input array, computed element-wise.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.tanh" title="mxnet.ndarray.sparse.tanh"><code class="xref py py-obj docutils literal"><span class="pre">tanh</span></code></a></td> |
| <td>Returns the hyperbolic tangent of the input array, computed element-wise.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.arcsinh" title="mxnet.ndarray.sparse.arcsinh"><code class="xref py py-obj docutils literal"><span class="pre">arcsinh</span></code></a></td> |
| <td>Returns the element-wise inverse hyperbolic sine of the input array, computed element-wise.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.arctanh" title="mxnet.ndarray.sparse.arctanh"><code class="xref py py-obj docutils literal"><span class="pre">arctanh</span></code></a></td> |
| <td>Returns the element-wise inverse hyperbolic tangent of the input array, computed element-wise.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="section" id="rounding"> |
| <span id="rounding"></span><h3>Rounding<a class="headerlink" href="#rounding" title="Permalink to this headline">¶</a></h3> |
| <table border="1" class="longtable docutils"> |
| <colgroup> |
| <col width="10%"/> |
| <col width="90%"/> |
| </colgroup> |
| <tbody valign="top"> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.round" title="mxnet.ndarray.sparse.round"><code class="xref py py-obj docutils literal"><span class="pre">round</span></code></a></td> |
| <td>Returns element-wise rounded value to the nearest integer of the input.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.rint" title="mxnet.ndarray.sparse.rint"><code class="xref py py-obj docutils literal"><span class="pre">rint</span></code></a></td> |
| <td>Returns element-wise rounded value to the nearest integer of the input.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.fix" title="mxnet.ndarray.sparse.fix"><code class="xref py py-obj docutils literal"><span class="pre">fix</span></code></a></td> |
| <td>Returns element-wise rounded value to the nearest integer towards zero of the input.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.floor" title="mxnet.ndarray.sparse.floor"><code class="xref py py-obj docutils literal"><span class="pre">floor</span></code></a></td> |
| <td>Returns element-wise floor of the input.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.ceil" title="mxnet.ndarray.sparse.ceil"><code class="xref py py-obj docutils literal"><span class="pre">ceil</span></code></a></td> |
| <td>Returns element-wise ceiling of the input.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.trunc" title="mxnet.ndarray.sparse.trunc"><code class="xref py py-obj docutils literal"><span class="pre">trunc</span></code></a></td> |
| <td>Return the element-wise truncated value of the input.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="section" id="exponents-and-logarithms"> |
| <span id="exponents-and-logarithms"></span><h3>Exponents and logarithms<a class="headerlink" href="#exponents-and-logarithms" title="Permalink to this headline">¶</a></h3> |
| <table border="1" class="longtable docutils"> |
| <colgroup> |
| <col width="10%"/> |
| <col width="90%"/> |
| </colgroup> |
| <tbody valign="top"> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.expm1" title="mxnet.ndarray.sparse.expm1"><code class="xref py py-obj docutils literal"><span class="pre">expm1</span></code></a></td> |
| <td>Returns <code class="docutils literal"><span class="pre">exp(x)</span> <span class="pre">-</span> <span class="pre">1</span></code> computed element-wise on the input.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.log1p" title="mxnet.ndarray.sparse.log1p"><code class="xref py py-obj docutils literal"><span class="pre">log1p</span></code></a></td> |
| <td>Returns element-wise <code class="docutils literal"><span class="pre">log(1</span> <span class="pre">+</span> <span class="pre">x)</span></code> value of the input.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="section" id="powers"> |
| <span id="powers"></span><h3>Powers<a class="headerlink" href="#powers" title="Permalink to this headline">¶</a></h3> |
| <table border="1" class="longtable docutils"> |
| <colgroup> |
| <col width="10%"/> |
| <col width="90%"/> |
| </colgroup> |
| <tbody valign="top"> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.sqrt" title="mxnet.ndarray.sparse.sqrt"><code class="xref py py-obj docutils literal"><span class="pre">sqrt</span></code></a></td> |
| <td>Returns element-wise square-root value of the input.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.square" title="mxnet.ndarray.sparse.square"><code class="xref py py-obj docutils literal"><span class="pre">square</span></code></a></td> |
| <td>Returns element-wise squared value of the input.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="section" id="miscellaneous"> |
| <span id="miscellaneous"></span><h3>Miscellaneous<a class="headerlink" href="#miscellaneous" title="Permalink to this headline">¶</a></h3> |
| <table border="1" class="longtable docutils"> |
| <colgroup> |
| <col width="10%"/> |
| <col width="90%"/> |
| </colgroup> |
| <tbody valign="top"> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.abs" title="mxnet.ndarray.sparse.abs"><code class="xref py py-obj docutils literal"><span class="pre">abs</span></code></a></td> |
| <td>Returns element-wise absolute value of the input.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.sign" title="mxnet.ndarray.sparse.sign"><code class="xref py py-obj docutils literal"><span class="pre">sign</span></code></a></td> |
| <td>Returns element-wise sign of the input.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="section" id="more"> |
| <span id="more"></span><h3>More<a class="headerlink" href="#more" title="Permalink to this headline">¶</a></h3> |
| <table border="1" class="longtable docutils"> |
| <colgroup> |
| <col width="10%"/> |
| <col width="90%"/> |
| </colgroup> |
| <tbody valign="top"> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.ndarray.sparse.make_loss" title="mxnet.ndarray.sparse.make_loss"><code class="xref py py-obj docutils literal"><span class="pre">make_loss</span></code></a></td> |
| <td>Make your own loss function in network construction.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.ndarray.sparse.stop_gradient" title="mxnet.ndarray.sparse.stop_gradient"><code class="xref py py-obj docutils literal"><span class="pre">stop_gradient</span></code></a></td> |
| <td>Stops gradient computation.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| </div> |
| <div class="section" id="api-reference"> |
| <span id="api-reference"></span><h2>API Reference<a class="headerlink" href="#api-reference" title="Permalink to this headline">¶</a></h2> |
| <script src="../../../_static/js/auto_module_index.js" type="text/javascript"></script><dl class="class"> |
| <dt id="mxnet.ndarray.sparse.CSRNDArray"> |
| <em class="property">class </em><code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">CSRNDArray</code><span class="sig-paren">(</span><em>handle</em>, <em>writable=True</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.CSRNDArray" title="Permalink to this definition">¶</a></dt> |
| <dd><p>A sparse representation of 2D NDArray in the Compressed Sparse Row format.</p> |
| <p>A CSRNDArray represents an NDArray as three separate arrays: <cite>data</cite>, |
| <cite>indptr</cite> and <cite>indices</cite>. It uses the CSR representation where the column indices for |
| row i are stored in <code class="docutils literal"><span class="pre">indices[indptr[i]:indptr[i+1]]</span></code> and their corresponding values are stored |
| in <code class="docutils literal"><span class="pre">data[indptr[i]:indptr[i+1]]</span></code>.</p> |
| <p>The column indices for a given row are expected to be sorted in ascending order. |
| Duplicate column entries for the same row are not allowed.</p> |
| <p class="rubric">Example</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">a</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">]])</span> |
| <span class="gp">>>> </span><span class="n">a</span> <span class="o">=</span> <span class="n">a</span><span class="o">.</span><span class="n">tostype</span><span class="p">(</span><span class="s1">'csr'</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">a</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">array([ 1., 2., 3.], dtype=float32)</span> |
| <span class="gp">>>> </span><span class="n">a</span><span class="o">.</span><span class="n">indices</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">array([1, 0, 2])</span> |
| <span class="gp">>>> </span><span class="n">a</span><span class="o">.</span><span class="n">indptr</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">array([0, 1, 2, 2, 3])</span> |
| </pre></div> |
| </div> |
| <div class="admonition seealso"> |
| <p class="first admonition-title">See also</p> |
| <dl class="last docutils"> |
| <dt><a class="reference internal" href="#mxnet.ndarray.sparse.csr_matrix" title="mxnet.ndarray.sparse.csr_matrix"><code class="xref py py-class docutils literal"><span class="pre">csr_matrix</span></code></a></dt> |
| <dd>Several ways to construct a CSRNDArray</dd> |
| </dl> |
| </div> |
| <dl class="method"> |
| <dt id="mxnet.ndarray.sparse.CSRNDArray.__getitem__"> |
| <code class="descname">__getitem__</code><span class="sig-paren">(</span><em>key</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.CSRNDArray.__getitem__" title="Permalink to this definition">¶</a></dt> |
| <dd><p>x.__getitem__(i) <=> x[i]</p> |
| <p>Returns a sliced view of this array.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>key</strong> (<em>int or slice</em>) – Indexing key.</td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">indptr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">6</span><span class="p">])</span> |
| <span class="gp">>>> </span><span class="n">indices</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span> |
| <span class="gp">>>> </span><span class="n">data</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">])</span> |
| <span class="gp">>>> </span><span class="n">a</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">sparse</span><span class="o">.</span><span class="n">csr_matrix</span><span class="p">((</span><span class="n">data</span><span class="p">,</span> <span class="n">indices</span><span class="p">,</span> <span class="n">indptr</span><span class="p">),</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span> |
| <span class="gp">>>> </span><span class="n">a</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">array([[ 1., 0., 2.],</span> |
| <span class="go"> [ 0., 0., 3.],</span> |
| <span class="go"> [ 4., 5., 6.]], dtype=float32)</span> |
| <span class="gp">>>> </span><span class="n">a</span><span class="p">[</span><span class="mi">1</span><span class="p">:</span><span class="mi">2</span><span class="p">]</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">array([[ 0., 0., 3.]], dtype=float32)</span> |
| <span class="gp">>>> </span><span class="n">a</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">array([[ 0., 0., 3.]], dtype=float32)</span> |
| <span class="gp">>>> </span><span class="n">a</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">array([[ 4., 5., 6.]], dtype=float32)</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.ndarray.sparse.CSRNDArray.__setitem__"> |
| <code class="descname">__setitem__</code><span class="sig-paren">(</span><em>key</em>, <em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.CSRNDArray.__setitem__" title="Permalink to this definition">¶</a></dt> |
| <dd><p>x.__setitem__(i, y) <=> x[i]=y</p> |
| <p>Set self[key] to value. Only slice key [:] is supported.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple"> |
| <li><strong>key</strong> (<a class="reference internal" href="../symbol/symbol.html#mxnet.symbol.Symbol.slice" title="mxnet.symbol.Symbol.slice"><em>slice</em></a>) – The indexing key.</li> |
| <li><strong>value</strong> (<em>NDArray or CSRNDArray or numpy.ndarray</em>) – The value to set.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">src</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">sparse</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="s1">'csr'</span><span class="p">,</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span><span class="mi">3</span><span class="p">))</span> |
| <span class="gp">>>> </span><span class="n">src</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">array([[ 0., 0., 0.],</span> |
| <span class="go"> [ 0., 0., 0.],</span> |
| <span class="go"> [ 0., 0., 0.]], dtype=float32)</span> |
| <span class="gp">>>> </span><span class="c1"># assign CSRNDArray with same storage type</span> |
| <span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="s1">'row_sparse'</span><span class="p">,</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span><span class="mi">3</span><span class="p">))</span><span class="o">.</span><span class="n">tostype</span><span class="p">(</span><span class="s1">'csr'</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">x</span><span class="p">[:]</span> <span class="o">=</span> <span class="n">src</span> |
| <span class="gp">>>> </span><span class="n">x</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">array([[ 1., 1., 1.],</span> |
| <span class="go"> [ 1., 1., 1.],</span> |
| <span class="go"> [ 1., 1., 1.]], dtype=float32)</span> |
| <span class="gp">>>> </span><span class="c1"># assign NDArray to CSRNDArray</span> |
| <span class="gp">>>> </span><span class="n">x</span><span class="p">[:]</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">ones</span><span class="p">((</span><span class="mi">3</span><span class="p">,</span><span class="mi">3</span><span class="p">))</span> <span class="o">*</span> <span class="mi">2</span> |
| <span class="gp">>>> </span><span class="n">x</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">array([[ 2., 2., 2.],</span> |
| <span class="go"> [ 2., 2., 2.],</span> |
| <span class="go"> [ 2., 2., 2.]], dtype=float32)</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.ndarray.sparse.CSRNDArray.indices"> |
| <code class="descname">indices</code><a class="headerlink" href="#mxnet.ndarray.sparse.CSRNDArray.indices" title="Permalink to this definition">¶</a></dt> |
| <dd><p>A deep copy NDArray of the indices array of the CSRNDArray. |
| This generates a deep copy of the column indices of the current <cite>csr</cite> matrix.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">This CSRNDArray’s indices array.</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body"><a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray">NDArray</a></td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.ndarray.sparse.CSRNDArray.indptr"> |
| <code class="descname">indptr</code><a class="headerlink" href="#mxnet.ndarray.sparse.CSRNDArray.indptr" title="Permalink to this definition">¶</a></dt> |
| <dd><p>A deep copy NDArray of the indptr array of the CSRNDArray. |
| This generates a deep copy of the <cite>indptr</cite> of the current <cite>csr</cite> matrix.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">This CSRNDArray’s indptr array.</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body"><a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray">NDArray</a></td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.ndarray.sparse.CSRNDArray.data"> |
| <code class="descname">data</code><a class="headerlink" href="#mxnet.ndarray.sparse.CSRNDArray.data" title="Permalink to this definition">¶</a></dt> |
| <dd><p>A deep copy NDArray of the data array of the CSRNDArray. |
| This generates a deep copy of the <cite>data</cite> of the current <cite>csr</cite> matrix.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">This CSRNDArray’s data array.</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body"><a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray">NDArray</a></td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.ndarray.sparse.CSRNDArray.tostype"> |
| <code class="descname">tostype</code><span class="sig-paren">(</span><em>stype</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.CSRNDArray.tostype" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Return a copy of the array with chosen storage type.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">A copy of the array with the chosen storage stype</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">NDArray or CSRNDArray</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.ndarray.sparse.CSRNDArray.copyto"> |
| <code class="descname">copyto</code><span class="sig-paren">(</span><em>other</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.CSRNDArray.copyto" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Copies the value of this array to another array.</p> |
| <p>If <code class="docutils literal"><span class="pre">other</span></code> is a <code class="docutils literal"><span class="pre">NDArray</span></code> or <code class="docutils literal"><span class="pre">CSRNDArray</span></code> object, then <code class="docutils literal"><span class="pre">other.shape</span></code> and |
| <code class="docutils literal"><span class="pre">self.shape</span></code> should be the same. This function copies the value from |
| <code class="docutils literal"><span class="pre">self</span></code> to <code class="docutils literal"><span class="pre">other</span></code>.</p> |
| <p>If <code class="docutils literal"><span class="pre">other</span></code> is a context, a new <code class="docutils literal"><span class="pre">CSRNDArray</span></code> will be first created on |
| the target context, and the value of <code class="docutils literal"><span class="pre">self</span></code> is copied.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>other</strong> (<em>NDArray or CSRNDArray or Context</em>) – The destination array or context.</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The copied array. If <code class="docutils literal"><span class="pre">other</span></code> is an <code class="docutils literal"><span class="pre">NDArray</span></code> or <code class="docutils literal"><span class="pre">CSRNDArray</span></code>, then the return |
| value and <code class="docutils literal"><span class="pre">other</span></code> will point to the same <code class="docutils literal"><span class="pre">NDArray</span></code> or <code class="docutils literal"><span class="pre">CSRNDArray</span></code>.</td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">NDArray or CSRNDArray</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.ndarray.sparse.CSRNDArray.as_in_context"> |
| <code class="descname">as_in_context</code><span class="sig-paren">(</span><em>context</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.CSRNDArray.as_in_context" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns an array on the target device with the same value as this array.</p> |
| <p>If the target context is the same as <code class="docutils literal"><span class="pre">self.context</span></code>, then <code class="docutils literal"><span class="pre">self</span></code> is |
| returned. Otherwise, a copy is made.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>context</strong> (<em>Context</em>) – The target context.</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The target array.</td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">NDArray, CSRNDArray or RowSparseNDArray</td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">ones</span><span class="p">((</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">))</span> |
| <span class="gp">>>> </span><span class="n">y</span> <span class="o">=</span> <span class="n">x</span><span class="o">.</span><span class="n">as_in_context</span><span class="p">(</span><span class="n">mx</span><span class="o">.</span><span class="n">cpu</span><span class="p">())</span> |
| <span class="gp">>>> </span><span class="n">y</span> <span class="ow">is</span> <span class="n">x</span> |
| <span class="go">True</span> |
| <span class="gp">>>> </span><span class="n">z</span> <span class="o">=</span> <span class="n">x</span><span class="o">.</span><span class="n">as_in_context</span><span class="p">(</span><span class="n">mx</span><span class="o">.</span><span class="n">gpu</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span> |
| <span class="gp">>>> </span><span class="n">z</span> <span class="ow">is</span> <span class="n">x</span> |
| <span class="go">False</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.ndarray.sparse.CSRNDArray.asnumpy"> |
| <code class="descname">asnumpy</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.CSRNDArray.asnumpy" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Return a dense <code class="docutils literal"><span class="pre">numpy.ndarray</span></code> object with value copied from this array</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.ndarray.sparse.CSRNDArray.asscalar"> |
| <code class="descname">asscalar</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.CSRNDArray.asscalar" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns a scalar whose value is copied from this array.</p> |
| <p>This function is equivalent to <code class="docutils literal"><span class="pre">self.asnumpy()[0]</span></code>. This NDArray must have shape (1,).</p> |
| <p class="rubric">Examples</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">ones</span><span class="p">((</span><span class="mi">1</span><span class="p">,),</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">'int32'</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">x</span><span class="o">.</span><span class="n">asscalar</span><span class="p">()</span> |
| <span class="go">1</span> |
| <span class="gp">>>> </span><span class="nb">type</span><span class="p">(</span><span class="n">x</span><span class="o">.</span><span class="n">asscalar</span><span class="p">())</span> |
| <span class="go"><type 'numpy.int32'></span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.ndarray.sparse.CSRNDArray.astype"> |
| <code class="descname">astype</code><span class="sig-paren">(</span><em>dtype</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.CSRNDArray.astype" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns a copy of the array after casting to a specified type. |
| :param dtype: The type of the returned array. |
| :type dtype: numpy.dtype or str</p> |
| <p class="rubric">Examples</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">sparse</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="s1">'row_sparse'</span><span class="p">,</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">),</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">'float32'</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">y</span> <span class="o">=</span> <span class="n">x</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="s1">'int32'</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">y</span><span class="o">.</span><span class="n">dtype</span> |
| <span class="go"><type 'numpy.int32'></span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.ndarray.sparse.CSRNDArray.context"> |
| <code class="descname">context</code><a class="headerlink" href="#mxnet.ndarray.sparse.CSRNDArray.context" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Device context of the array.</p> |
| <p class="rubric">Examples</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">])</span> |
| <span class="gp">>>> </span><span class="n">x</span><span class="o">.</span><span class="n">context</span> |
| <span class="go">cpu(0)</span> |
| <span class="gp">>>> </span><span class="nb">type</span><span class="p">(</span><span class="n">x</span><span class="o">.</span><span class="n">context</span><span class="p">)</span> |
| <span class="go"><class 'mxnet.context.Context'></span> |
| <span class="gp">>>> </span><span class="n">y</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">),</span> <span class="n">mx</span><span class="o">.</span><span class="n">gpu</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span> |
| <span class="gp">>>> </span><span class="n">y</span><span class="o">.</span><span class="n">context</span> |
| <span class="go">gpu(0)</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.ndarray.sparse.CSRNDArray.copy"> |
| <code class="descname">copy</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.CSRNDArray.copy" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Makes a copy of this <code class="docutils literal"><span class="pre">NDArray</span></code>, keeping the same context.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">The copied array</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">NDArray, CSRNDArray or RowSparseNDArray</td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">ones</span><span class="p">((</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">))</span> |
| <span class="gp">>>> </span><span class="n">y</span> <span class="o">=</span> <span class="n">x</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> |
| <span class="gp">>>> </span><span class="n">y</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">array([[ 1., 1., 1.],</span> |
| <span class="go"> [ 1., 1., 1.]], dtype=float32)</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.ndarray.sparse.CSRNDArray.dtype"> |
| <code class="descname">dtype</code><a class="headerlink" href="#mxnet.ndarray.sparse.CSRNDArray.dtype" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Data-type of the array’s elements.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">This NDArray’s data type.</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">numpy.dtype</td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">))</span> |
| <span class="gp">>>> </span><span class="n">x</span><span class="o">.</span><span class="n">dtype</span> |
| <span class="go"><type 'numpy.float32'></span> |
| <span class="gp">>>> </span><span class="n">y</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">),</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">'int32'</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">y</span><span class="o">.</span><span class="n">dtype</span> |
| <span class="go"><type 'numpy.int32'></span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.ndarray.sparse.CSRNDArray.shape"> |
| <code class="descname">shape</code><a class="headerlink" href="#mxnet.ndarray.sparse.CSRNDArray.shape" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Tuple of array dimensions.</p> |
| <p class="rubric">Examples</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">])</span> |
| <span class="gp">>>> </span><span class="n">x</span><span class="o">.</span><span class="n">shape</span> |
| <span class="go">(4L,)</span> |
| <span class="gp">>>> </span><span class="n">y</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">))</span> |
| <span class="gp">>>> </span><span class="n">y</span><span class="o">.</span><span class="n">shape</span> |
| <span class="go">(2L, 3L, 4L)</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.ndarray.sparse.CSRNDArray.slice"> |
| <code class="descname">slice</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.CSRNDArray.slice" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Convenience fluent method for <a class="reference internal" href="#mxnet.ndarray.sparse.slice" title="mxnet.ndarray.sparse.slice"><code class="xref py py-func docutils literal"><span class="pre">slice()</span></code></a>.</p> |
| <p>The arguments are the same as for <a class="reference internal" href="#mxnet.ndarray.sparse.slice" title="mxnet.ndarray.sparse.slice"><code class="xref py py-func docutils literal"><span class="pre">slice()</span></code></a>, with |
| this array as data.</p> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.ndarray.sparse.CSRNDArray.stype"> |
| <code class="descname">stype</code><a class="headerlink" href="#mxnet.ndarray.sparse.CSRNDArray.stype" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Storage-type of the array.</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.ndarray.sparse.CSRNDArray.wait_to_read"> |
| <code class="descname">wait_to_read</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.CSRNDArray.wait_to_read" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Waits until all previous write operations on the current array are finished.</p> |
| <p>This method guarantees that all previous write operations that pushed |
| into the backend engine for execution are actually finished.</p> |
| <p class="rubric">Examples</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">time</span> |
| <span class="gp">>>> </span><span class="n">tic</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> |
| <span class="gp">>>> </span><span class="n">a</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">ones</span><span class="p">((</span><span class="mi">1000</span><span class="p">,</span><span class="mi">1000</span><span class="p">))</span> |
| <span class="gp">>>> </span><span class="n">b</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">a</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="k">print</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">-</span> <span class="n">tic</span><span class="p">)</span> |
| <span class="go">0.003854036331176758</span> |
| <span class="gp">>>> </span><span class="n">b</span><span class="o">.</span><span class="n">wait_to_read</span><span class="p">()</span> |
| <span class="gp">>>> </span><span class="k">print</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">-</span> <span class="n">tic</span><span class="p">)</span> |
| <span class="go">0.0893700122833252</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.ndarray.sparse.CSRNDArray.zeros_like"> |
| <code class="descname">zeros_like</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.CSRNDArray.zeros_like" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Convenience fluent method for <a class="reference internal" href="#mxnet.ndarray.sparse.zeros_like" title="mxnet.ndarray.sparse.zeros_like"><code class="xref py py-func docutils literal"><span class="pre">zeros_like()</span></code></a>.</p> |
| <p>The arguments are the same as for <a class="reference internal" href="#mxnet.ndarray.sparse.zeros_like" title="mxnet.ndarray.sparse.zeros_like"><code class="xref py py-func docutils literal"><span class="pre">zeros_like()</span></code></a>, with |
| this array as data.</p> |
| </dd></dl> |
| </dd></dl> |
| <dl class="class"> |
| <dt id="mxnet.ndarray.sparse.RowSparseNDArray"> |
| <em class="property">class </em><code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">RowSparseNDArray</code><span class="sig-paren">(</span><em>handle</em>, <em>writable=True</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.RowSparseNDArray" title="Permalink to this definition">¶</a></dt> |
| <dd><p>A sparse representation of a set of NDArray row slices at given indices.</p> |
| <p>A RowSparseNDArray represents a multidimensional NDArray using two separate arrays: <cite>data</cite> and |
| <cite>indices</cite>. The number of dimensions has to be at least 2.</p> |
| <ul class="simple"> |
| <li>data: an NDArray of any dtype with shape [D0, D1, ..., Dn].</li> |
| <li>indices: a 1-D int64 NDArray with shape [D0] with values sorted in ascending order.</li> |
| </ul> |
| <p>The <cite>indices</cite> stores the indices of the row slices with non-zeros, |
| while the values are stored in <cite>data</cite>. The corresponding NDArray <code class="docutils literal"><span class="pre">dense</span></code> |
| represented by RowSparseNDArray <code class="docutils literal"><span class="pre">rsp</span></code> has</p> |
| <p><code class="docutils literal"><span class="pre">dense[rsp.indices[i],</span> <span class="pre">:,</span> <span class="pre">:,</span> <span class="pre">:,</span> <span class="pre">...]</span> <span class="pre">=</span> <span class="pre">rsp.data[i,</span> <span class="pre">:,</span> <span class="pre">:,</span> <span class="pre">:,</span> <span class="pre">...]</span></code></p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">dense</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">array([[ 1., 2., 3.],</span> |
| <span class="go"> [ 0., 0., 0.],</span> |
| <span class="go"> [ 4., 0., 5.],</span> |
| <span class="go"> [ 0., 0., 0.],</span> |
| <span class="go"> [ 0., 0., 0.]], dtype=float32)</span> |
| <span class="gp">>>> </span><span class="n">rsp</span> <span class="o">=</span> <span class="n">dense</span><span class="o">.</span><span class="n">tostype</span><span class="p">(</span><span class="s1">'row_sparse'</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">rsp</span><span class="o">.</span><span class="n">indices</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">array([0, 2], dtype=int64)</span> |
| <span class="gp">>>> </span><span class="n">rsp</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">array([[ 1., 2., 3.],</span> |
| <span class="go"> [ 4., 0., 5.]], dtype=float32)</span> |
| </pre></div> |
| </div> |
| <p>A RowSparseNDArray is typically used to represent non-zero row slices of a large NDArray |
| of shape [LARGE0, D1, .. , Dn] where LARGE0 >> D0 and most row slices are zeros.</p> |
| <p>RowSparseNDArray is used principally in the definition of gradients for operations |
| that have sparse gradients (e.g. sparse dot and sparse embedding).</p> |
| <div class="admonition seealso"> |
| <p class="first admonition-title">See also</p> |
| <dl class="last docutils"> |
| <dt><a class="reference internal" href="#mxnet.ndarray.sparse.row_sparse_array" title="mxnet.ndarray.sparse.row_sparse_array"><code class="xref py py-class docutils literal"><span class="pre">row_sparse_array</span></code></a></dt> |
| <dd>Several ways to construct a RowSparseNDArray</dd> |
| </dl> |
| </div> |
| <dl class="method"> |
| <dt id="mxnet.ndarray.sparse.RowSparseNDArray.__getitem__"> |
| <code class="descname">__getitem__</code><span class="sig-paren">(</span><em>key</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.RowSparseNDArray.__getitem__" title="Permalink to this definition">¶</a></dt> |
| <dd><p>x.__getitem__(i) <=> x[i]</p> |
| <p>Returns a sliced view of this array.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>key</strong> (<a class="reference internal" href="../symbol/symbol.html#mxnet.symbol.Symbol.slice" title="mxnet.symbol.Symbol.slice"><em>slice</em></a>) – Indexing key.</td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">sparse</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="s1">'row_sparse'</span><span class="p">,</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span> |
| <span class="gp">>>> </span><span class="n">x</span><span class="p">[:]</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">array([[ 0., 0., 0.],</span> |
| <span class="go"> [ 0., 0., 0.]], dtype=float32)</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.ndarray.sparse.RowSparseNDArray.__setitem__"> |
| <code class="descname">__setitem__</code><span class="sig-paren">(</span><em>key</em>, <em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.RowSparseNDArray.__setitem__" title="Permalink to this definition">¶</a></dt> |
| <dd><p>x.__setitem__(i, y) <=> x[i]=y</p> |
| <p>Set self[key] to value. Only slice key [:] is supported.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple"> |
| <li><strong>key</strong> (<a class="reference internal" href="../symbol/symbol.html#mxnet.symbol.Symbol.slice" title="mxnet.symbol.Symbol.slice"><em>slice</em></a>) – The indexing key.</li> |
| <li><strong>value</strong> (<em>NDArray or numpy.ndarray</em>) – The value to set.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">src</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">row_sparse</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">]],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span><span class="mi">3</span><span class="p">))</span> |
| <span class="gp">>>> </span><span class="n">src</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">array([[ 1., 0., 2.],</span> |
| <span class="go"> [ 0., 0., 0.],</span> |
| <span class="go"> [ 4., 5., 6.]], dtype=float32)</span> |
| <span class="gp">>>> </span><span class="c1"># assign RowSparseNDArray with same storage type</span> |
| <span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">sparse</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="s1">'row_sparse'</span><span class="p">,</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span><span class="mi">3</span><span class="p">))</span> |
| <span class="gp">>>> </span><span class="n">x</span><span class="p">[:]</span> <span class="o">=</span> <span class="n">src</span> |
| <span class="gp">>>> </span><span class="n">x</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">array([[ 1., 0., 2.],</span> |
| <span class="go"> [ 0., 0., 0.],</span> |
| <span class="go"> [ 4., 5., 6.]], dtype=float32)</span> |
| <span class="gp">>>> </span><span class="c1"># assign NDArray to RowSparseNDArray</span> |
| <span class="gp">>>> </span><span class="n">x</span><span class="p">[:]</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">ones</span><span class="p">((</span><span class="mi">3</span><span class="p">,</span><span class="mi">3</span><span class="p">))</span> |
| <span class="gp">>>> </span><span class="n">x</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">array([[ 1., 1., 1.],</span> |
| <span class="go"> [ 1., 1., 1.],</span> |
| <span class="go"> [ 1., 1., 1.]], dtype=float32)</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.ndarray.sparse.RowSparseNDArray.indices"> |
| <code class="descname">indices</code><a class="headerlink" href="#mxnet.ndarray.sparse.RowSparseNDArray.indices" title="Permalink to this definition">¶</a></dt> |
| <dd><p>A deep copy NDArray of the indices array of the RowSparseNDArray. |
| This generates a deep copy of the row indices of the current <cite>row_sparse</cite> matrix.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">This RowSparseNDArray’s indices array.</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body"><a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray">NDArray</a></td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.ndarray.sparse.RowSparseNDArray.data"> |
| <code class="descname">data</code><a class="headerlink" href="#mxnet.ndarray.sparse.RowSparseNDArray.data" title="Permalink to this definition">¶</a></dt> |
| <dd><p>A deep copy NDArray of the data array of the RowSparseNDArray. |
| This generates a deep copy of the <cite>data</cite> of the current <cite>row_sparse</cite> matrix.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">This RowSparseNDArray’s data array.</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body"><a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray">NDArray</a></td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.ndarray.sparse.RowSparseNDArray.tostype"> |
| <code class="descname">tostype</code><span class="sig-paren">(</span><em>stype</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.RowSparseNDArray.tostype" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Return a copy of the array with chosen storage type.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">A copy of the array with the chosen storage stype</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">NDArray or RowSparseNDArray</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.ndarray.sparse.RowSparseNDArray.copyto"> |
| <code class="descname">copyto</code><span class="sig-paren">(</span><em>other</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.RowSparseNDArray.copyto" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Copies the value of this array to another array.</p> |
| <p>If <code class="docutils literal"><span class="pre">other</span></code> is a <code class="docutils literal"><span class="pre">NDArray</span></code> or <code class="docutils literal"><span class="pre">RowSparseNDArray</span></code> object, then <code class="docutils literal"><span class="pre">other.shape</span></code> |
| and <code class="docutils literal"><span class="pre">self.shape</span></code> should be the same. This function copies the value from |
| <code class="docutils literal"><span class="pre">self</span></code> to <code class="docutils literal"><span class="pre">other</span></code>.</p> |
| <p>If <code class="docutils literal"><span class="pre">other</span></code> is a context, a new <code class="docutils literal"><span class="pre">RowSparseNDArray</span></code> will be first created on |
| the target context, and the value of <code class="docutils literal"><span class="pre">self</span></code> is copied.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>other</strong> (<em>NDArray or RowSparseNDArray or Context</em>) – The destination array or context.</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The copied array. If <code class="docutils literal"><span class="pre">other</span></code> is an <code class="docutils literal"><span class="pre">NDArray</span></code> or <code class="docutils literal"><span class="pre">RowSparseNDArray</span></code>, then the |
| return value and <code class="docutils literal"><span class="pre">other</span></code> will point to the same <code class="docutils literal"><span class="pre">NDArray</span></code> or <code class="docutils literal"><span class="pre">RowSparseNDArray</span></code>.</td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">NDArray or RowSparseNDArray</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.ndarray.sparse.RowSparseNDArray.as_in_context"> |
| <code class="descname">as_in_context</code><span class="sig-paren">(</span><em>context</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.RowSparseNDArray.as_in_context" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns an array on the target device with the same value as this array.</p> |
| <p>If the target context is the same as <code class="docutils literal"><span class="pre">self.context</span></code>, then <code class="docutils literal"><span class="pre">self</span></code> is |
| returned. Otherwise, a copy is made.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>context</strong> (<em>Context</em>) – The target context.</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The target array.</td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">NDArray, CSRNDArray or RowSparseNDArray</td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">ones</span><span class="p">((</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">))</span> |
| <span class="gp">>>> </span><span class="n">y</span> <span class="o">=</span> <span class="n">x</span><span class="o">.</span><span class="n">as_in_context</span><span class="p">(</span><span class="n">mx</span><span class="o">.</span><span class="n">cpu</span><span class="p">())</span> |
| <span class="gp">>>> </span><span class="n">y</span> <span class="ow">is</span> <span class="n">x</span> |
| <span class="go">True</span> |
| <span class="gp">>>> </span><span class="n">z</span> <span class="o">=</span> <span class="n">x</span><span class="o">.</span><span class="n">as_in_context</span><span class="p">(</span><span class="n">mx</span><span class="o">.</span><span class="n">gpu</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span> |
| <span class="gp">>>> </span><span class="n">z</span> <span class="ow">is</span> <span class="n">x</span> |
| <span class="go">False</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.ndarray.sparse.RowSparseNDArray.asnumpy"> |
| <code class="descname">asnumpy</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.RowSparseNDArray.asnumpy" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Return a dense <code class="docutils literal"><span class="pre">numpy.ndarray</span></code> object with value copied from this array</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.ndarray.sparse.RowSparseNDArray.asscalar"> |
| <code class="descname">asscalar</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.RowSparseNDArray.asscalar" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns a scalar whose value is copied from this array.</p> |
| <p>This function is equivalent to <code class="docutils literal"><span class="pre">self.asnumpy()[0]</span></code>. This NDArray must have shape (1,).</p> |
| <p class="rubric">Examples</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">ones</span><span class="p">((</span><span class="mi">1</span><span class="p">,),</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">'int32'</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">x</span><span class="o">.</span><span class="n">asscalar</span><span class="p">()</span> |
| <span class="go">1</span> |
| <span class="gp">>>> </span><span class="nb">type</span><span class="p">(</span><span class="n">x</span><span class="o">.</span><span class="n">asscalar</span><span class="p">())</span> |
| <span class="go"><type 'numpy.int32'></span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.ndarray.sparse.RowSparseNDArray.astype"> |
| <code class="descname">astype</code><span class="sig-paren">(</span><em>dtype</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.RowSparseNDArray.astype" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns a copy of the array after casting to a specified type. |
| :param dtype: The type of the returned array. |
| :type dtype: numpy.dtype or str</p> |
| <p class="rubric">Examples</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">sparse</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="s1">'row_sparse'</span><span class="p">,</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">),</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">'float32'</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">y</span> <span class="o">=</span> <span class="n">x</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="s1">'int32'</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">y</span><span class="o">.</span><span class="n">dtype</span> |
| <span class="go"><type 'numpy.int32'></span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.ndarray.sparse.RowSparseNDArray.ceil"> |
| <code class="descname">ceil</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.RowSparseNDArray.ceil" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Convenience fluent method for <a class="reference internal" href="#mxnet.ndarray.sparse.ceil" title="mxnet.ndarray.sparse.ceil"><code class="xref py py-func docutils literal"><span class="pre">ceil()</span></code></a>.</p> |
| <p>The arguments are the same as for <a class="reference internal" href="#mxnet.ndarray.sparse.ceil" title="mxnet.ndarray.sparse.ceil"><code class="xref py py-func docutils literal"><span class="pre">ceil()</span></code></a>, with |
| this array as data.</p> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.ndarray.sparse.RowSparseNDArray.context"> |
| <code class="descname">context</code><a class="headerlink" href="#mxnet.ndarray.sparse.RowSparseNDArray.context" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Device context of the array.</p> |
| <p class="rubric">Examples</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">])</span> |
| <span class="gp">>>> </span><span class="n">x</span><span class="o">.</span><span class="n">context</span> |
| <span class="go">cpu(0)</span> |
| <span class="gp">>>> </span><span class="nb">type</span><span class="p">(</span><span class="n">x</span><span class="o">.</span><span class="n">context</span><span class="p">)</span> |
| <span class="go"><class 'mxnet.context.Context'></span> |
| <span class="gp">>>> </span><span class="n">y</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">),</span> <span class="n">mx</span><span class="o">.</span><span class="n">gpu</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span> |
| <span class="gp">>>> </span><span class="n">y</span><span class="o">.</span><span class="n">context</span> |
| <span class="go">gpu(0)</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.ndarray.sparse.RowSparseNDArray.copy"> |
| <code class="descname">copy</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.RowSparseNDArray.copy" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Makes a copy of this <code class="docutils literal"><span class="pre">NDArray</span></code>, keeping the same context.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">The copied array</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">NDArray, CSRNDArray or RowSparseNDArray</td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">ones</span><span class="p">((</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">))</span> |
| <span class="gp">>>> </span><span class="n">y</span> <span class="o">=</span> <span class="n">x</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> |
| <span class="gp">>>> </span><span class="n">y</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">array([[ 1., 1., 1.],</span> |
| <span class="go"> [ 1., 1., 1.]], dtype=float32)</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.ndarray.sparse.RowSparseNDArray.dtype"> |
| <code class="descname">dtype</code><a class="headerlink" href="#mxnet.ndarray.sparse.RowSparseNDArray.dtype" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Data-type of the array’s elements.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">This NDArray’s data type.</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">numpy.dtype</td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">))</span> |
| <span class="gp">>>> </span><span class="n">x</span><span class="o">.</span><span class="n">dtype</span> |
| <span class="go"><type 'numpy.float32'></span> |
| <span class="gp">>>> </span><span class="n">y</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">),</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">'int32'</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">y</span><span class="o">.</span><span class="n">dtype</span> |
| <span class="go"><type 'numpy.int32'></span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.ndarray.sparse.RowSparseNDArray.fix"> |
| <code class="descname">fix</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.RowSparseNDArray.fix" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Convenience fluent method for <a class="reference internal" href="#mxnet.ndarray.sparse.fix" title="mxnet.ndarray.sparse.fix"><code class="xref py py-func docutils literal"><span class="pre">fix()</span></code></a>.</p> |
| <p>The arguments are the same as for <a class="reference internal" href="#mxnet.ndarray.sparse.fix" title="mxnet.ndarray.sparse.fix"><code class="xref py py-func docutils literal"><span class="pre">fix()</span></code></a>, with |
| this array as data.</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.ndarray.sparse.RowSparseNDArray.floor"> |
| <code class="descname">floor</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.RowSparseNDArray.floor" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Convenience fluent method for <a class="reference internal" href="#mxnet.ndarray.sparse.floor" title="mxnet.ndarray.sparse.floor"><code class="xref py py-func docutils literal"><span class="pre">floor()</span></code></a>.</p> |
| <p>The arguments are the same as for <a class="reference internal" href="#mxnet.ndarray.sparse.floor" title="mxnet.ndarray.sparse.floor"><code class="xref py py-func docutils literal"><span class="pre">floor()</span></code></a>, with |
| this array as data.</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.ndarray.sparse.RowSparseNDArray.rint"> |
| <code class="descname">rint</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.RowSparseNDArray.rint" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Convenience fluent method for <a class="reference internal" href="#mxnet.ndarray.sparse.rint" title="mxnet.ndarray.sparse.rint"><code class="xref py py-func docutils literal"><span class="pre">rint()</span></code></a>.</p> |
| <p>The arguments are the same as for <a class="reference internal" href="#mxnet.ndarray.sparse.rint" title="mxnet.ndarray.sparse.rint"><code class="xref py py-func docutils literal"><span class="pre">rint()</span></code></a>, with |
| this array as data.</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.ndarray.sparse.RowSparseNDArray.round"> |
| <code class="descname">round</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.RowSparseNDArray.round" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Convenience fluent method for <a class="reference internal" href="#mxnet.ndarray.sparse.round" title="mxnet.ndarray.sparse.round"><code class="xref py py-func docutils literal"><span class="pre">round()</span></code></a>.</p> |
| <p>The arguments are the same as for <a class="reference internal" href="#mxnet.ndarray.sparse.round" title="mxnet.ndarray.sparse.round"><code class="xref py py-func docutils literal"><span class="pre">round()</span></code></a>, with |
| this array as data.</p> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.ndarray.sparse.RowSparseNDArray.shape"> |
| <code class="descname">shape</code><a class="headerlink" href="#mxnet.ndarray.sparse.RowSparseNDArray.shape" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Tuple of array dimensions.</p> |
| <p class="rubric">Examples</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">])</span> |
| <span class="gp">>>> </span><span class="n">x</span><span class="o">.</span><span class="n">shape</span> |
| <span class="go">(4L,)</span> |
| <span class="gp">>>> </span><span class="n">y</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">))</span> |
| <span class="gp">>>> </span><span class="n">y</span><span class="o">.</span><span class="n">shape</span> |
| <span class="go">(2L, 3L, 4L)</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.ndarray.sparse.RowSparseNDArray.stype"> |
| <code class="descname">stype</code><a class="headerlink" href="#mxnet.ndarray.sparse.RowSparseNDArray.stype" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Storage-type of the array.</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.ndarray.sparse.RowSparseNDArray.trunc"> |
| <code class="descname">trunc</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.RowSparseNDArray.trunc" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Convenience fluent method for <a class="reference internal" href="#mxnet.ndarray.sparse.trunc" title="mxnet.ndarray.sparse.trunc"><code class="xref py py-func docutils literal"><span class="pre">trunc()</span></code></a>.</p> |
| <p>The arguments are the same as for <a class="reference internal" href="#mxnet.ndarray.sparse.trunc" title="mxnet.ndarray.sparse.trunc"><code class="xref py py-func docutils literal"><span class="pre">trunc()</span></code></a>, with |
| this array as data.</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.ndarray.sparse.RowSparseNDArray.wait_to_read"> |
| <code class="descname">wait_to_read</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.RowSparseNDArray.wait_to_read" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Waits until all previous write operations on the current array are finished.</p> |
| <p>This method guarantees that all previous write operations that pushed |
| into the backend engine for execution are actually finished.</p> |
| <p class="rubric">Examples</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">time</span> |
| <span class="gp">>>> </span><span class="n">tic</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> |
| <span class="gp">>>> </span><span class="n">a</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">ones</span><span class="p">((</span><span class="mi">1000</span><span class="p">,</span><span class="mi">1000</span><span class="p">))</span> |
| <span class="gp">>>> </span><span class="n">b</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">a</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="k">print</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">-</span> <span class="n">tic</span><span class="p">)</span> |
| <span class="go">0.003854036331176758</span> |
| <span class="gp">>>> </span><span class="n">b</span><span class="o">.</span><span class="n">wait_to_read</span><span class="p">()</span> |
| <span class="gp">>>> </span><span class="k">print</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">-</span> <span class="n">tic</span><span class="p">)</span> |
| <span class="go">0.0893700122833252</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.ndarray.sparse.RowSparseNDArray.zeros_like"> |
| <code class="descname">zeros_like</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.RowSparseNDArray.zeros_like" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Convenience fluent method for <a class="reference internal" href="#mxnet.ndarray.sparse.zeros_like" title="mxnet.ndarray.sparse.zeros_like"><code class="xref py py-func docutils literal"><span class="pre">zeros_like()</span></code></a>.</p> |
| <p>The arguments are the same as for <a class="reference internal" href="#mxnet.ndarray.sparse.zeros_like" title="mxnet.ndarray.sparse.zeros_like"><code class="xref py py-func docutils literal"><span class="pre">zeros_like()</span></code></a>, with |
| this array as data.</p> |
| </dd></dl> |
| </dd></dl> |
| <span class="target" id="module-mxnet.ndarray.sparse"></span><p>Sparse NDArray API of MXNet.</p> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.csr_matrix"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">csr_matrix</code><span class="sig-paren">(</span><em>arg1</em>, <em>shape=None</em>, <em>ctx=None</em>, <em>dtype=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.csr_matrix" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Creates a <cite>CSRNDArray</cite>, an 2D array with compressed sparse row (CSR) format.</p> |
| <p>The CSRNDArray can be instantiated in several ways:</p> |
| <ul class="simple"> |
| <li><dl class="first docutils"> |
| <dt>csr_matrix(D):</dt> |
| <dd><dl class="first last docutils"> |
| <dt>to construct a CSRNDArray with a dense 2D array <code class="docutils literal"><span class="pre">D</span></code></dt> |
| <dd><ul class="first last"> |
| <li><strong>D</strong> (<em>array_like</em>) - An object exposing the array interface, an object whose <cite>__array__</cite> method returns an array, or any (nested) sequence.</li> |
| <li><strong>ctx</strong> (<em>Context, optional</em>) - Device context (default is the current default context).</li> |
| <li><strong>dtype</strong> (<em>str or numpy.dtype, optional</em>) - The data type of the output array. The default dtype is <code class="docutils literal"><span class="pre">D.dtype</span></code> if <code class="docutils literal"><span class="pre">D</span></code> is an NDArray or numpy.ndarray, float32 otherwise.</li> |
| </ul> |
| </dd> |
| </dl> |
| </dd> |
| </dl> |
| </li> |
| <li><dl class="first docutils"> |
| <dt>csr_matrix(S)</dt> |
| <dd><dl class="first last docutils"> |
| <dt>to construct a CSRNDArray with a sparse 2D array <code class="docutils literal"><span class="pre">S</span></code></dt> |
| <dd><ul class="first last"> |
| <li><strong>S</strong> (<em>CSRNDArray or scipy.sparse.csr.csr_matrix</em>) - A sparse matrix.</li> |
| <li><strong>ctx</strong> (<em>Context, optional</em>) - Device context (default is the current default context).</li> |
| <li><strong>dtype</strong> (<em>str or numpy.dtype, optional</em>) - The data type of the output array. The default dtype is <code class="docutils literal"><span class="pre">S.dtype</span></code>.</li> |
| </ul> |
| </dd> |
| </dl> |
| </dd> |
| </dl> |
| </li> |
| <li><dl class="first docutils"> |
| <dt>csr_matrix((M, N))</dt> |
| <dd><dl class="first last docutils"> |
| <dt>to construct an empty CSRNDArray with shape <code class="docutils literal"><span class="pre">(M,</span> <span class="pre">N)</span></code></dt> |
| <dd><ul class="first last"> |
| <li><strong>M</strong> (<em>int</em>) - Number of rows in the matrix</li> |
| <li><strong>N</strong> (<em>int</em>) - Number of columns in the matrix</li> |
| <li><strong>ctx</strong> (<em>Context, optional</em>) - Device context (default is the current default context).</li> |
| <li><strong>dtype</strong> (<em>str or numpy.dtype, optional</em>) - The data type of the output array. The default dtype is float32.</li> |
| </ul> |
| </dd> |
| </dl> |
| </dd> |
| </dl> |
| </li> |
| <li><dl class="first docutils"> |
| <dt>csr_matrix((data, indices, indptr))</dt> |
| <dd><dl class="first last docutils"> |
| <dt>to construct a CSRNDArray based on the definition of compressed sparse row format using three separate arrays, where the column indices for row i are stored in <code class="docutils literal"><span class="pre">indices[indptr[i]:indptr[i+1]]</span></code> and their corresponding values are stored in <code class="docutils literal"><span class="pre">data[indptr[i]:indptr[i+1]]</span></code>. The column indices for a given row are expected to be <strong>sorted in ascending order.</strong> Duplicate column entries for the same row are not allowed.</dt> |
| <dd><ul class="first last"> |
| <li><strong>data</strong> (<em>array_like</em>) - An object exposing the array interface, which holds all the non-zero entries of the matrix in row-major order.</li> |
| <li><strong>indices</strong> (<em>array_like</em>) - An object exposing the array interface, which stores the column index for each non-zero element in <code class="docutils literal"><span class="pre">data</span></code>.</li> |
| <li><strong>indptr</strong> (<em>array_like</em>) - An object exposing the array interface, which stores the offset into <code class="docutils literal"><span class="pre">data</span></code> of the first non-zero element number of each row of the matrix.</li> |
| <li><strong>shape</strong> (<em>tuple of int, optional</em>) - The shape of the array. The default shape is inferred from the indices and indptr arrays.</li> |
| <li><strong>ctx</strong> (<em>Context, optional</em>) - Device context (default is the current default context).</li> |
| <li><strong>dtype</strong> (<em>str or numpy.dtype, optional</em>) - The data type of the output array. The default dtype is <code class="docutils literal"><span class="pre">data.dtype</span></code> if <code class="docutils literal"><span class="pre">data</span></code> is an NDArray or numpy.ndarray, float32 otherwise.</li> |
| </ul> |
| </dd> |
| </dl> |
| </dd> |
| </dl> |
| </li> |
| </ul> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>arg1</strong> (<em>NDArray, CSRNDArray, numpy.ndarray, scipy.sparse.csr.csr_matrix, tuple of int or tuple of array_like</em>) – The argument to help instantiate the csr matrix. See above for further details.</li> |
| <li><strong>shape</strong> (<em>tuple of int, optional</em>) – The shape of the csr matrix.</li> |
| <li><strong>ctx</strong> (<em>Context, optional</em>) – Device context (default is the current default context).</li> |
| <li><strong>dtype</strong> (<em>str or numpy.dtype, optional</em>) – The data type of the output array.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">A <cite>CSRNDArray</cite> with the <cite>csr</cite> storage representation.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last"><a class="reference internal" href="#mxnet.ndarray.sparse.CSRNDArray" title="mxnet.ndarray.sparse.CSRNDArray">CSRNDArray</a></p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Example</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">a</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">sparse</span><span class="o">.</span><span class="n">csr_matrix</span><span class="p">(([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">]),</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span> |
| <span class="gp">>>> </span><span class="n">a</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">array([[ 0., 1., 0.],</span> |
| <span class="go"> [ 2., 0., 0.],</span> |
| <span class="go"> [ 0., 0., 0.],</span> |
| <span class="go"> [ 0., 0., 3.]], dtype=float32)</span> |
| </pre></div> |
| </div> |
| <div class="admonition seealso"> |
| <p class="first admonition-title">See also</p> |
| <dl class="last docutils"> |
| <dt><a class="reference internal" href="#mxnet.ndarray.sparse.CSRNDArray" title="mxnet.ndarray.sparse.CSRNDArray"><code class="xref py py-func docutils literal"><span class="pre">CSRNDArray()</span></code></a></dt> |
| <dd>MXNet NDArray in compressed sparse row format.</dd> |
| </dl> |
| </div> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.row_sparse_array"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">row_sparse_array</code><span class="sig-paren">(</span><em>arg1</em>, <em>shape=None</em>, <em>ctx=None</em>, <em>dtype=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.row_sparse_array" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Creates a <cite>RowSparseNDArray</cite>, a multidimensional row sparse array with a set of tensor slices at given indices.</p> |
| <p>The RowSparseNDArray can be instantiated in several ways:</p> |
| <ul> |
| <li><dl class="first docutils"> |
| <dt>row_sparse_array(D):</dt> |
| <dd><dl class="first last docutils"> |
| <dt>to construct a RowSparseNDArray with a dense ndarray <code class="docutils literal"><span class="pre">D</span></code></dt> |
| <dd><ul class="first last simple"> |
| <li><strong>D</strong> (<em>array_like</em>) - An object exposing the array interface, an object whose <cite>__array__</cite> method returns an array, or any (nested) sequence.</li> |
| <li><strong>ctx</strong> (<em>Context, optional</em>) - Device context (default is the current default context).</li> |
| <li><strong>dtype</strong> (<em>str or numpy.dtype, optional</em>) - The data type of the output array. The default dtype is <code class="docutils literal"><span class="pre">D.dtype</span></code> if <code class="docutils literal"><span class="pre">D</span></code> is an NDArray or numpy.ndarray, float32 otherwise.</li> |
| </ul> |
| </dd> |
| </dl> |
| </dd> |
| </dl> |
| </li> |
| <li><dl class="first docutils"> |
| <dt>row_sparse_array(S)</dt> |
| <dd><dl class="first last docutils"> |
| <dt>to construct a RowSparseNDArray with a sparse ndarray <code class="docutils literal"><span class="pre">S</span></code></dt> |
| <dd><ul class="first last simple"> |
| <li><strong>S</strong> (<em>RowSparseNDArray</em>) - A sparse ndarray.</li> |
| <li><strong>ctx</strong> (<em>Context, optional</em>) - Device context (default is the current default context).</li> |
| <li><strong>dtype</strong> (<em>str or numpy.dtype, optional</em>) - The data type of the output array. The default dtype is <code class="docutils literal"><span class="pre">S.dtype</span></code>.</li> |
| </ul> |
| </dd> |
| </dl> |
| </dd> |
| </dl> |
| </li> |
| <li><dl class="first docutils"> |
| <dt>row_sparse_array((D0, D1 .. Dn))</dt> |
| <dd><dl class="first last docutils"> |
| <dt>to construct an empty RowSparseNDArray with shape <code class="docutils literal"><span class="pre">(D0,</span> <span class="pre">D1,</span> <span class="pre">...</span> <span class="pre">Dn)</span></code></dt> |
| <dd><ul class="first last simple"> |
| <li><strong>D0, D1 .. Dn</strong> (<em>int</em>) - The shape of the ndarray</li> |
| <li><strong>ctx</strong> (<em>Context, optional</em>) - Device context (default is the current default context).</li> |
| <li><strong>dtype</strong> (<em>str or numpy.dtype, optional</em>) - The data type of the output array. The default dtype is float32.</li> |
| </ul> |
| </dd> |
| </dl> |
| </dd> |
| </dl> |
| </li> |
| <li><dl class="first docutils"> |
| <dt>row_sparse_array((data, indices))</dt> |
| <dd><p class="first">to construct a RowSparseNDArray based on the definition of row sparse format using two separate arrays, where the <cite>indices</cite> stores the indices of the row slices with non-zeros, |
| while the values are stored in <cite>data</cite>. The corresponding NDArray <code class="docutils literal"><span class="pre">dense</span></code> |
| represented by RowSparseNDArray <code class="docutils literal"><span class="pre">rsp</span></code> has <code class="docutils literal"><span class="pre">dense[rsp.indices[i],</span> <span class="pre">:,</span> <span class="pre">:,</span> <span class="pre">:,</span> <span class="pre">...]</span> <span class="pre">=</span> <span class="pre">rsp.data[i,</span> <span class="pre">:,</span> <span class="pre">:,</span> <span class="pre">:,</span> <span class="pre">...]</span></code> |
| The row indices for are expected to be <strong>sorted in ascending order.</strong> - <strong>data</strong> (<em>array_like</em>) - An object exposing the array interface, which holds all the non-zero row slices of the array.</p> |
| <blockquote class="last"> |
| <div><ul class="simple"> |
| <li><strong>indices</strong> (<em>array_like</em>) - An object exposing the array interface, which stores the row index for each row slice with non-zero elements.</li> |
| <li><strong>shape</strong> (<em>tuple of int, optional</em>) - The shape of the array. The default shape is inferred from the indices and indptr arrays.</li> |
| <li><strong>ctx</strong> (<em>Context, optional</em>) - Device context (default is the current default context).</li> |
| <li><strong>dtype</strong> (<em>str or numpy.dtype, optional</em>) - The data type of the output array. The default dtype is float32.</li> |
| </ul> |
| </div></blockquote> |
| </dd> |
| </dl> |
| </li> |
| </ul> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>arg1</strong> (<em>NDArray, numpy.ndarray, RowSparseNDArray, tuple of int or tuple of array_like</em>) – The argument to help instantiate the row sparse ndarray. See above for further details.</li> |
| <li><strong>shape</strong> (<em>tuple of int, optional</em>) – The shape of the row sparse ndarray.</li> |
| <li><strong>ctx</strong> (<em>Context, optional</em>) – Device context (default is the current default context).</li> |
| <li><strong>dtype</strong> (<em>str or numpy.dtype, optional</em>) – The data type of the output array.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">An <cite>RowSparseNDArray</cite> with the <cite>row_sparse</cite> storage representation.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last"><a class="reference internal" href="#mxnet.ndarray.sparse.RowSparseNDArray" title="mxnet.ndarray.sparse.RowSparseNDArray">RowSparseNDArray</a></p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Example</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">a</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">sparse</span><span class="o">.</span><span class="n">row_sparse_array</span><span class="p">(([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">]],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">]),</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="mi">6</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span> |
| <span class="gp">>>> </span><span class="n">a</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">array([[ 0., 0.],</span> |
| <span class="go"> [ 1., 2.],</span> |
| <span class="go"> [ 0., 0.],</span> |
| <span class="go"> [ 0., 0.],</span> |
| <span class="go"> [ 3., 4.],</span> |
| <span class="go"> [ 0., 0.]], dtype=float32)</span> |
| </pre></div> |
| </div> |
| <div class="admonition seealso"> |
| <p class="first admonition-title">See also</p> |
| <dl class="last docutils"> |
| <dt><a class="reference internal" href="#mxnet.ndarray.sparse.RowSparseNDArray" title="mxnet.ndarray.sparse.RowSparseNDArray"><code class="xref py py-func docutils literal"><span class="pre">RowSparseNDArray()</span></code></a></dt> |
| <dd>MXNet NDArray in row sparse format.</dd> |
| </dl> |
| </div> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.ElementWiseSum"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">ElementWiseSum</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.ElementWiseSum" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Adds all input arguments element-wise.</p> |
| <div class="math"> |
| \[add\_n(a_1, a_2, ..., a_n) = a_1 + a_2 + ... + a_n\]</div> |
| <p><code class="docutils literal"><span class="pre">add_n</span></code> is potentially more efficient than calling <code class="docutils literal"><span class="pre">add</span></code> by <cite>n</cite> times.</p> |
| <p>The storage type of <code class="docutils literal"><span class="pre">add_n</span></code> output depends on storage types of inputs</p> |
| <ul class="simple"> |
| <li>add_n(row_sparse, row_sparse, ..) = row_sparse</li> |
| <li>otherwise, <code class="docutils literal"><span class="pre">add_n</span></code> generates output with default storage</li> |
| </ul> |
| <p>Defined in src/operator/tensor/elemwise_sum.cc:L122</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>args</strong> (<em>NDArray[]</em>) – Positional input arguments</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.abs"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">abs</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.abs" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns element-wise absolute value of the input.</p> |
| <p>Example:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="nb">abs</span><span class="p">([</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span> <span class="o">=</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">]</span> |
| </pre></div> |
| </div> |
| <p>The storage type of <code class="docutils literal"><span class="pre">abs</span></code> output depends upon the input storage type:</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li>abs(default) = default</li> |
| <li>abs(row_sparse) = row_sparse</li> |
| </ul> |
| </div></blockquote> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L387</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.add_n"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">add_n</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.add_n" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Adds all input arguments element-wise.</p> |
| <div class="math"> |
| \[add\_n(a_1, a_2, ..., a_n) = a_1 + a_2 + ... + a_n\]</div> |
| <p><code class="docutils literal"><span class="pre">add_n</span></code> is potentially more efficient than calling <code class="docutils literal"><span class="pre">add</span></code> by <cite>n</cite> times.</p> |
| <p>The storage type of <code class="docutils literal"><span class="pre">add_n</span></code> output depends on storage types of inputs</p> |
| <ul class="simple"> |
| <li>add_n(row_sparse, row_sparse, ..) = row_sparse</li> |
| <li>otherwise, <code class="docutils literal"><span class="pre">add_n</span></code> generates output with default storage</li> |
| </ul> |
| <p>Defined in src/operator/tensor/elemwise_sum.cc:L122</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>args</strong> (<em>NDArray[]</em>) – Positional input arguments</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.arccos"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">arccos</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.arccos" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns element-wise inverse cosine of the input array.</p> |
| <p>The input should be in range <cite>[-1, 1]</cite>. |
| The output is in the closed interval <span class="math">\([0, \pi]\)</span></p> |
| <div class="math"> |
| \[arccos([-1, -.707, 0, .707, 1]) = [\pi, 3\pi/4, \pi/2, \pi/4, 0]\]</div> |
| <p>The storage type of <code class="docutils literal"><span class="pre">arccos</span></code> output is always dense</p> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_trig.cc:L123</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.arccosh"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">arccosh</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.arccosh" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns the element-wise inverse hyperbolic cosine of the input array, computed element-wise.</p> |
| <p>The storage type of <code class="docutils literal"><span class="pre">arccosh</span></code> output is always dense</p> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_trig.cc:L264</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.arcsin"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">arcsin</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.arcsin" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns element-wise inverse sine of the input array.</p> |
| <p>The input should be in the range <cite>[-1, 1]</cite>. |
| The output is in the closed interval of [<span class="math">\(-\pi/2\)</span>, <span class="math">\(\pi/2\)</span>].</p> |
| <div class="math"> |
| \[arcsin([-1, -.707, 0, .707, 1]) = [-\pi/2, -\pi/4, 0, \pi/4, \pi/2]\]</div> |
| <p>The storage type of <code class="docutils literal"><span class="pre">arcsin</span></code> output depends upon the input storage type:</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li>arcsin(default) = default</li> |
| <li>arcsin(row_sparse) = row_sparse</li> |
| </ul> |
| </div></blockquote> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_trig.cc:L104</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.arcsinh"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">arcsinh</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.arcsinh" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns the element-wise inverse hyperbolic sine of the input array, computed element-wise.</p> |
| <p>The storage type of <code class="docutils literal"><span class="pre">arcsinh</span></code> output depends upon the input storage type:</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li>arcsinh(default) = default</li> |
| <li>arcsinh(row_sparse) = row_sparse</li> |
| </ul> |
| </div></blockquote> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_trig.cc:L250</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.arctan"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">arctan</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.arctan" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns element-wise inverse tangent of the input array.</p> |
| <p>The output is in the closed interval <span class="math">\([-\pi/2, \pi/2]\)</span></p> |
| <div class="math"> |
| \[arctan([-1, 0, 1]) = [-\pi/4, 0, \pi/4]\]</div> |
| <p>The storage type of <code class="docutils literal"><span class="pre">arctan</span></code> output depends upon the input storage type:</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li>arctan(default) = default</li> |
| <li>arctan(row_sparse) = row_sparse</li> |
| </ul> |
| </div></blockquote> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_trig.cc:L144</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.arctanh"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">arctanh</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.arctanh" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns the element-wise inverse hyperbolic tangent of the input array, computed element-wise.</p> |
| <p>The storage type of <code class="docutils literal"><span class="pre">arctanh</span></code> output depends upon the input storage type:</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li>arctanh(default) = default</li> |
| <li>arctanh(row_sparse) = row_sparse</li> |
| </ul> |
| </div></blockquote> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_trig.cc:L281</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.cast_storage"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">cast_storage</code><span class="sig-paren">(</span><em>data=None</em>, <em>stype=_Null</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.cast_storage" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Casts tensor storage type to the new type.</p> |
| <p>When an NDArray with default storage type is cast to csr or row_sparse storage, |
| the result is compact, which means:</p> |
| <ul class="simple"> |
| <li>for csr, zero values will not be retained</li> |
| <li>for row_sparse, row slices of all zeros will not be retained</li> |
| </ul> |
| <p>The storage type of <code class="docutils literal"><span class="pre">cast_storage</span></code> output depends on stype parameter:</p> |
| <ul class="simple"> |
| <li>cast_storage(csr, ‘default’) = default</li> |
| <li>cast_storage(row_sparse, ‘default’) = default</li> |
| <li>cast_storage(default, ‘csr’) = csr</li> |
| <li>cast_storage(default, ‘row_sparse’) = row_sparse</li> |
| </ul> |
| <p>Example:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">dense</span> <span class="o">=</span> <span class="p">[[</span> <span class="mf">0.</span><span class="p">,</span> <span class="mf">1.</span><span class="p">,</span> <span class="mf">0.</span><span class="p">],</span> |
| <span class="p">[</span> <span class="mf">2.</span><span class="p">,</span> <span class="mf">0.</span><span class="p">,</span> <span class="mf">3.</span><span class="p">],</span> |
| <span class="p">[</span> <span class="mf">0.</span><span class="p">,</span> <span class="mf">0.</span><span class="p">,</span> <span class="mf">0.</span><span class="p">],</span> |
| <span class="p">[</span> <span class="mf">0.</span><span class="p">,</span> <span class="mf">0.</span><span class="p">,</span> <span class="mf">0.</span><span class="p">]]</span> |
| |
| <span class="c1"># cast to row_sparse storage type</span> |
| <span class="n">rsp</span> <span class="o">=</span> <span class="n">cast_storage</span><span class="p">(</span><span class="n">dense</span><span class="p">,</span> <span class="s1">'row_sparse'</span><span class="p">)</span> |
| <span class="n">rsp</span><span class="o">.</span><span class="n">indices</span> <span class="o">=</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span> |
| <span class="n">rsp</span><span class="o">.</span><span class="n">values</span> <span class="o">=</span> <span class="p">[[</span> <span class="mf">0.</span><span class="p">,</span> <span class="mf">1.</span><span class="p">,</span> <span class="mf">0.</span><span class="p">],</span> |
| <span class="p">[</span> <span class="mf">2.</span><span class="p">,</span> <span class="mf">0.</span><span class="p">,</span> <span class="mf">3.</span><span class="p">]]</span> |
| |
| <span class="c1"># cast to csr storage type</span> |
| <span class="n">csr</span> <span class="o">=</span> <span class="n">cast_storage</span><span class="p">(</span><span class="n">dense</span><span class="p">,</span> <span class="s1">'csr'</span><span class="p">)</span> |
| <span class="n">csr</span><span class="o">.</span><span class="n">indices</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">]</span> |
| <span class="n">csr</span><span class="o">.</span><span class="n">values</span> <span class="o">=</span> <span class="p">[</span> <span class="mf">1.</span><span class="p">,</span> <span class="mf">2.</span><span class="p">,</span> <span class="mf">3.</span><span class="p">]</span> |
| <span class="n">csr</span><span class="o">.</span><span class="n">indptr</span> <span class="o">=</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">]</span> |
| </pre></div> |
| </div> |
| <p>Defined in src/operator/tensor/cast_storage.cc:L69</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input.</li> |
| <li><strong>stype</strong> (<em>{'csr', 'default', 'row_sparse'}, required</em>) – Output storage type.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.ceil"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">ceil</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.ceil" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns element-wise ceiling of the input.</p> |
| <p>The ceil of the scalar x is the smallest integer i, such that i >= x.</p> |
| <p>Example:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">ceil</span><span class="p">([</span><span class="o">-</span><span class="mf">2.1</span><span class="p">,</span> <span class="o">-</span><span class="mf">1.9</span><span class="p">,</span> <span class="mf">1.5</span><span class="p">,</span> <span class="mf">1.9</span><span class="p">,</span> <span class="mf">2.1</span><span class="p">])</span> <span class="o">=</span> <span class="p">[</span><span class="o">-</span><span class="mf">2.</span><span class="p">,</span> <span class="o">-</span><span class="mf">1.</span><span class="p">,</span> <span class="mf">2.</span><span class="p">,</span> <span class="mf">2.</span><span class="p">,</span> <span class="mf">3.</span><span class="p">]</span> |
| </pre></div> |
| </div> |
| <p>The storage type of <code class="docutils literal"><span class="pre">ceil</span></code> output depends upon the input storage type:</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li>ceil(default) = default</li> |
| <li>ceil(row_sparse) = row_sparse</li> |
| </ul> |
| </div></blockquote> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L464</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.cos"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">cos</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.cos" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Computes the element-wise cosine of the input array.</p> |
| <p>The input should be in radians (<span class="math">\(2\pi\)</span> rad equals 360 degrees).</p> |
| <div class="math"> |
| \[cos([0, \pi/4, \pi/2]) = [1, 0.707, 0]\]</div> |
| <p>The storage type of <code class="docutils literal"><span class="pre">cos</span></code> output is always dense</p> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_trig.cc:L63</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.cosh"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">cosh</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.cosh" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns the hyperbolic cosine of the input array, computed element-wise.</p> |
| <div class="math"> |
| \[cosh(x) = 0.5\times(exp(x) + exp(-x))\]</div> |
| <p>The storage type of <code class="docutils literal"><span class="pre">cosh</span></code> output is always dense</p> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_trig.cc:L216</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.degrees"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">degrees</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.degrees" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Converts each element of the input array from radians to degrees.</p> |
| <div class="math"> |
| \[degrees([0, \pi/2, \pi, 3\pi/2, 2\pi]) = [0, 90, 180, 270, 360]\]</div> |
| <p>The storage type of <code class="docutils literal"><span class="pre">degrees</span></code> output depends upon the input storage type:</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li>degrees(default) = default</li> |
| <li>degrees(row_sparse) = row_sparse</li> |
| </ul> |
| </div></blockquote> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_trig.cc:L163</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.dot"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">dot</code><span class="sig-paren">(</span><em>lhs=None</em>, <em>rhs=None</em>, <em>transpose_a=_Null</em>, <em>transpose_b=_Null</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.dot" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Dot product of two arrays.</p> |
| <p><code class="docutils literal"><span class="pre">dot</span></code>‘s behavior depends on the input array dimensions:</p> |
| <ul> |
| <li><p class="first">1-D arrays: inner product of vectors</p> |
| </li> |
| <li><p class="first">2-D arrays: matrix multiplication</p> |
| </li> |
| <li><p class="first">N-D arrays: a sum product over the last axis of the first input and the first |
| axis of the second input</p> |
| <p>For example, given 3-D <code class="docutils literal"><span class="pre">x</span></code> with shape <cite>(n,m,k)</cite> and <code class="docutils literal"><span class="pre">y</span></code> with shape <cite>(k,r,s)</cite>, the |
| result array will have shape <cite>(n,m,r,s)</cite>. It is computed by:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">dot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">)[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">]</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span><span class="n">x</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,:]</span><span class="o">*</span><span class="n">y</span><span class="p">[:,</span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">])</span> |
| </pre></div> |
| </div> |
| <p>Example:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">x</span> <span class="o">=</span> <span class="n">reshape</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">6</span><span class="p">,</span><span class="mi">7</span><span class="p">],</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">))</span> |
| <span class="n">y</span> <span class="o">=</span> <span class="n">reshape</span><span class="p">([</span><span class="mi">7</span><span class="p">,</span><span class="mi">6</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">],</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">))</span> |
| <span class="n">dot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">)[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span> |
| <span class="nb">sum</span><span class="p">(</span><span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,:]</span><span class="o">*</span><span class="n">y</span><span class="p">[:,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">])</span> <span class="o">=</span> <span class="mi">0</span> |
| </pre></div> |
| </div> |
| </li> |
| </ul> |
| <p>The storage type of <code class="docutils literal"><span class="pre">dot</span></code> output depends on storage types of inputs and transpose options:</p> |
| <ul class="simple"> |
| <li>dot(csr, default) = default</li> |
| <li>dot(csr.T, default) = row_sparse</li> |
| <li>dot(csr, row_sparse) = default</li> |
| <li>otherwise, <code class="docutils literal"><span class="pre">dot</span></code> generates output with default storage</li> |
| </ul> |
| <p>Defined in src/operator/tensor/dot.cc:L61</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>lhs</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The first input</li> |
| <li><strong>rhs</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The second input</li> |
| <li><strong>transpose_a</strong> (<em>boolean, optional, default=0</em>) – If true then transpose the first input before dot.</li> |
| <li><strong>transpose_b</strong> (<em>boolean, optional, default=0</em>) – If true then transpose the second input before dot.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.elemwise_add"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">elemwise_add</code><span class="sig-paren">(</span><em>lhs=None</em>, <em>rhs=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.elemwise_add" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Adds arguments element-wise.</p> |
| <p>The storage type of <code class="docutils literal"><span class="pre">elemwise_add</span></code> output depends on storage types of inputs</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li>elemwise_add(row_sparse, row_sparse) = row_sparse</li> |
| <li>otherwise, <code class="docutils literal"><span class="pre">elemwise_add</span></code> generates output with default storage</li> |
| </ul> |
| </div></blockquote> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>lhs</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – first input</li> |
| <li><strong>rhs</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – second input</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.elemwise_div"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">elemwise_div</code><span class="sig-paren">(</span><em>lhs=None</em>, <em>rhs=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.elemwise_div" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Divides arguments element-wise.</p> |
| <p>The storage type of <code class="docutils literal"><span class="pre">elemwise_dev</span></code> output is always dense</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>lhs</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – first input</li> |
| <li><strong>rhs</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – second input</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.elemwise_mul"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">elemwise_mul</code><span class="sig-paren">(</span><em>lhs=None</em>, <em>rhs=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.elemwise_mul" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Multiplies arguments element-wise.</p> |
| <p>The storage type of <code class="docutils literal"><span class="pre">elemwise_mul</span></code> output depends on storage types of inputs</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li>elemwise_mul(default, default) = default</li> |
| <li>elemwise_mul(row_sparse, row_sparse) = row_sparse</li> |
| <li>elemwise_mul(default, row_sparse) = row_sparse</li> |
| <li>elemwise_mul(row_sparse, default) = row_sparse</li> |
| <li>otherwise, <code class="docutils literal"><span class="pre">elemwise_mul</span></code> generates output with default storage</li> |
| </ul> |
| </div></blockquote> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>lhs</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – first input</li> |
| <li><strong>rhs</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – second input</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.elemwise_sub"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">elemwise_sub</code><span class="sig-paren">(</span><em>lhs=None</em>, <em>rhs=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.elemwise_sub" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Subtracts arguments element-wise.</p> |
| <p>The storage type of <code class="docutils literal"><span class="pre">elemwise_sub</span></code> output depends on storage types of inputs</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li>elemwise_sub(row_sparse, row_sparse) = row_sparse</li> |
| <li>otherwise, <code class="docutils literal"><span class="pre">elemwise_add</span></code> generates output with default storage</li> |
| </ul> |
| </div></blockquote> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>lhs</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – first input</li> |
| <li><strong>rhs</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – second input</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.exp"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">exp</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.exp" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns element-wise exponential value of the input.</p> |
| <div class="math"> |
| \[exp(x) = e^x \approx 2.718^x\]</div> |
| <p>Example:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">exp</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span> <span class="o">=</span> <span class="p">[</span><span class="mf">1.</span><span class="p">,</span> <span class="mf">2.71828175</span><span class="p">,</span> <span class="mf">7.38905621</span><span class="p">]</span> |
| </pre></div> |
| </div> |
| <p>The storage type of <code class="docutils literal"><span class="pre">exp</span></code> output is always dense</p> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L638</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.expm1"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">expm1</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.expm1" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns <code class="docutils literal"><span class="pre">exp(x)</span> <span class="pre">-</span> <span class="pre">1</span></code> computed element-wise on the input.</p> |
| <p>This function provides greater precision than <code class="docutils literal"><span class="pre">exp(x)</span> <span class="pre">-</span> <span class="pre">1</span></code> for small values of <code class="docutils literal"><span class="pre">x</span></code>.</p> |
| <p>The storage type of <code class="docutils literal"><span class="pre">expm1</span></code> output depends upon the input storage type:</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li>expm1(default) = default</li> |
| <li>expm1(row_sparse) = row_sparse</li> |
| </ul> |
| </div></blockquote> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L717</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.fix"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">fix</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.fix" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns element-wise rounded value to the nearest integer towards zero of the input.</p> |
| <p>Example:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">fix</span><span class="p">([</span><span class="o">-</span><span class="mf">2.1</span><span class="p">,</span> <span class="o">-</span><span class="mf">1.9</span><span class="p">,</span> <span class="mf">1.9</span><span class="p">,</span> <span class="mf">2.1</span><span class="p">])</span> <span class="o">=</span> <span class="p">[</span><span class="o">-</span><span class="mf">2.</span><span class="p">,</span> <span class="o">-</span><span class="mf">1.</span><span class="p">,</span> <span class="mf">1.</span><span class="p">,</span> <span class="mf">2.</span><span class="p">]</span> |
| </pre></div> |
| </div> |
| <p>The storage type of <code class="docutils literal"><span class="pre">fix</span></code> output depends upon the input storage type:</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li>fix(default) = default</li> |
| <li>fix(row_sparse) = row_sparse</li> |
| </ul> |
| </div></blockquote> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L518</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.floor"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">floor</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.floor" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns element-wise floor of the input.</p> |
| <p>The floor of the scalar x is the largest integer i, such that i <= x.</p> |
| <p>Example:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">floor</span><span class="p">([</span><span class="o">-</span><span class="mf">2.1</span><span class="p">,</span> <span class="o">-</span><span class="mf">1.9</span><span class="p">,</span> <span class="mf">1.5</span><span class="p">,</span> <span class="mf">1.9</span><span class="p">,</span> <span class="mf">2.1</span><span class="p">])</span> <span class="o">=</span> <span class="p">[</span><span class="o">-</span><span class="mf">3.</span><span class="p">,</span> <span class="o">-</span><span class="mf">2.</span><span class="p">,</span> <span class="mf">1.</span><span class="p">,</span> <span class="mf">1.</span><span class="p">,</span> <span class="mf">2.</span><span class="p">]</span> |
| </pre></div> |
| </div> |
| <p>The storage type of <code class="docutils literal"><span class="pre">floor</span></code> output depends upon the input storage type:</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li>floor(default) = default</li> |
| <li>floor(row_sparse) = row_sparse</li> |
| </ul> |
| </div></blockquote> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L482</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.gamma"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">gamma</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.gamma" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns the gamma function (extension of the factorial function to the reals), computed element-wise on the input array.</p> |
| <p>The storage type of <code class="docutils literal"><span class="pre">gamma</span></code> output is always dense</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.gammaln"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">gammaln</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.gammaln" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns element-wise log of the absolute value of the gamma function of the input.</p> |
| <p>The storage type of <code class="docutils literal"><span class="pre">gammaln</span></code> output is always dense</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.log"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">log</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.log" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns element-wise Natural logarithmic value of the input.</p> |
| <p>The natural logarithm is logarithm in base <em>e</em>, so that <code class="docutils literal"><span class="pre">log(exp(x))</span> <span class="pre">=</span> <span class="pre">x</span></code></p> |
| <p>The storage type of <code class="docutils literal"><span class="pre">log</span></code> output is always dense</p> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L650</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.log10"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">log10</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.log10" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns element-wise Base-10 logarithmic value of the input.</p> |
| <p><code class="docutils literal"><span class="pre">10**log10(x)</span> <span class="pre">=</span> <span class="pre">x</span></code></p> |
| <p>The storage type of <code class="docutils literal"><span class="pre">log10</span></code> output is always dense</p> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L662</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.log1p"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">log1p</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.log1p" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns element-wise <code class="docutils literal"><span class="pre">log(1</span> <span class="pre">+</span> <span class="pre">x)</span></code> value of the input.</p> |
| <p>This function is more accurate than <code class="docutils literal"><span class="pre">log(1</span> <span class="pre">+</span> <span class="pre">x)</span></code> for small <code class="docutils literal"><span class="pre">x</span></code> so that |
| <span class="math">\(1+x\approx 1\)</span></p> |
| <p>The storage type of <code class="docutils literal"><span class="pre">log1p</span></code> output depends upon the input storage type:</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li>log1p(default) = default</li> |
| <li>log1p(row_sparse) = row_sparse</li> |
| </ul> |
| </div></blockquote> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L699</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.log2"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">log2</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.log2" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns element-wise Base-2 logarithmic value of the input.</p> |
| <p><code class="docutils literal"><span class="pre">2**log2(x)</span> <span class="pre">=</span> <span class="pre">x</span></code></p> |
| <p>The storage type of <code class="docutils literal"><span class="pre">log2</span></code> output is always dense</p> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L674</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.make_loss"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">make_loss</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.make_loss" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Make your own loss function in network construction.</p> |
| <p>This operator accepts a customized loss function symbol as a terminal loss and |
| the symbol should be an operator with no backward dependency. |
| The output of this function is the gradient of loss with respect to the input data.</p> |
| <p>For example, if you are a making a cross entropy loss function. Assume <code class="docutils literal"><span class="pre">out</span></code> is the |
| predicted output and <code class="docutils literal"><span class="pre">label</span></code> is the true label, then the cross entropy can be defined as:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">cross_entropy</span> <span class="o">=</span> <span class="n">label</span> <span class="o">*</span> <span class="n">log</span><span class="p">(</span><span class="n">out</span><span class="p">)</span> <span class="o">+</span> <span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">label</span><span class="p">)</span> <span class="o">*</span> <span class="n">log</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">out</span><span class="p">)</span> |
| <span class="n">loss</span> <span class="o">=</span> <span class="n">make_loss</span><span class="p">(</span><span class="n">cross_entropy</span><span class="p">)</span> |
| </pre></div> |
| </div> |
| <p>We will need to use <code class="docutils literal"><span class="pre">make_loss</span></code> when we are creating our own loss function or we want to |
| combine multiple loss functions. Also we may want to stop some variables’ gradients |
| from backpropagation. See more detail in <code class="docutils literal"><span class="pre">BlockGrad</span></code> or <code class="docutils literal"><span class="pre">stop_gradient</span></code>.</p> |
| <p>The storage type of <code class="docutils literal"><span class="pre">make_loss</span></code> output depends upon the input storage type:</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li>make_loss(default) = default</li> |
| <li>make_loss(row_sparse) = row_sparse</li> |
| </ul> |
| </div></blockquote> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L201</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.negative"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">negative</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.negative" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Numerical negative of the argument, element-wise.</p> |
| <p>The storage type of <code class="docutils literal"><span class="pre">negative</span></code> output depends upon the input storage type:</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li>negative(default) = default</li> |
| <li>negative(row_sparse) = row_sparse</li> |
| <li>negative(csr) = csr</li> |
| </ul> |
| </div></blockquote> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.radians"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">radians</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.radians" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Converts each element of the input array from degrees to radians.</p> |
| <div class="math"> |
| \[radians([0, 90, 180, 270, 360]) = [0, \pi/2, \pi, 3\pi/2, 2\pi]\]</div> |
| <p>The storage type of <code class="docutils literal"><span class="pre">radians</span></code> output depends upon the input storage type:</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li>radians(default) = default</li> |
| <li>radians(row_sparse) = row_sparse</li> |
| </ul> |
| </div></blockquote> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_trig.cc:L182</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.relu"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">relu</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.relu" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Computes rectified linear.</p> |
| <div class="math"> |
| \[max(features, 0)\]</div> |
| <p>The storage type of <code class="docutils literal"><span class="pre">relu</span></code> output depends upon the input storage type:</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li>relu(default) = default</li> |
| <li>relu(row_sparse) = row_sparse</li> |
| </ul> |
| </div></blockquote> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L84</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.retain"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">retain</code><span class="sig-paren">(</span><em>data=None</em>, <em>indices=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.retain" title="Permalink to this definition">¶</a></dt> |
| <dd><p>pick rows specified by user input index array from a row sparse matrix |
| and save them in the output sparse matrix.</p> |
| <p>Example:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">data</span> <span class="o">=</span> <span class="p">[[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">],</span> <span class="p">[</span><span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">]]</span> |
| <span class="n">indices</span> <span class="o">=</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">]</span> |
| <span class="n">shape</span> <span class="o">=</span> <span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span> |
| <span class="n">rsp_in</span> <span class="o">=</span> <span class="n">row_sparse</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">indices</span><span class="p">)</span> |
| <span class="n">to_retain</span> <span class="o">=</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">]</span> |
| <span class="n">rsp_out</span> <span class="o">=</span> <span class="n">retain</span><span class="p">(</span><span class="n">rsp_in</span><span class="p">,</span> <span class="n">to_retain</span><span class="p">)</span> |
| <span class="n">rsp_out</span><span class="o">.</span><span class="n">values</span> <span class="o">=</span> <span class="p">[[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">]]</span> |
| <span class="n">rsp_out</span><span class="o">.</span><span class="n">indices</span> <span class="o">=</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">]</span> |
| </pre></div> |
| </div> |
| <p>The storage type of <code class="docutils literal"><span class="pre">retain</span></code> output depends on storage types of inputs</p> |
| <ul class="simple"> |
| <li>retain(row_sparse, default) = row_sparse</li> |
| <li>otherwise, <code class="docutils literal"><span class="pre">retain</span></code> is not supported</li> |
| </ul> |
| <p>Defined in src/operator/tensor/sparse_retain.cc:L53</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array for sparse_retain operator.</li> |
| <li><strong>indices</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The index array of rows ids that will be retained.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.rint"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">rint</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.rint" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns element-wise rounded value to the nearest integer of the input.</p> |
| <div class="admonition note"> |
| <p class="first admonition-title">Note</p> |
| <ul class="last simple"> |
| <li>For input <code class="docutils literal"><span class="pre">n.5</span></code> <code class="docutils literal"><span class="pre">rint</span></code> returns <code class="docutils literal"><span class="pre">n</span></code> while <code class="docutils literal"><span class="pre">round</span></code> returns <code class="docutils literal"><span class="pre">n+1</span></code>.</li> |
| <li>For input <code class="docutils literal"><span class="pre">-n.5</span></code> both <code class="docutils literal"><span class="pre">rint</span></code> and <code class="docutils literal"><span class="pre">round</span></code> returns <code class="docutils literal"><span class="pre">-n-1</span></code>.</li> |
| </ul> |
| </div> |
| <p>Example:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">rint</span><span class="p">([</span><span class="o">-</span><span class="mf">1.5</span><span class="p">,</span> <span class="mf">1.5</span><span class="p">,</span> <span class="o">-</span><span class="mf">1.9</span><span class="p">,</span> <span class="mf">1.9</span><span class="p">,</span> <span class="mf">2.1</span><span class="p">])</span> <span class="o">=</span> <span class="p">[</span><span class="o">-</span><span class="mf">2.</span><span class="p">,</span> <span class="mf">1.</span><span class="p">,</span> <span class="o">-</span><span class="mf">2.</span><span class="p">,</span> <span class="mf">2.</span><span class="p">,</span> <span class="mf">2.</span><span class="p">]</span> |
| </pre></div> |
| </div> |
| <p>The storage type of <code class="docutils literal"><span class="pre">rint</span></code> output depends upon the input storage type:</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li>rint(default) = default</li> |
| <li>rint(row_sparse) = row_sparse</li> |
| </ul> |
| </div></blockquote> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L446</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.round"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">round</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.round" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns element-wise rounded value to the nearest integer of the input.</p> |
| <p>Example:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="nb">round</span><span class="p">([</span><span class="o">-</span><span class="mf">1.5</span><span class="p">,</span> <span class="mf">1.5</span><span class="p">,</span> <span class="o">-</span><span class="mf">1.9</span><span class="p">,</span> <span class="mf">1.9</span><span class="p">,</span> <span class="mf">2.1</span><span class="p">])</span> <span class="o">=</span> <span class="p">[</span><span class="o">-</span><span class="mf">2.</span><span class="p">,</span> <span class="mf">2.</span><span class="p">,</span> <span class="o">-</span><span class="mf">2.</span><span class="p">,</span> <span class="mf">2.</span><span class="p">,</span> <span class="mf">2.</span><span class="p">]</span> |
| </pre></div> |
| </div> |
| <p>The storage type of <code class="docutils literal"><span class="pre">round</span></code> output depends upon the input storage type:</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li>round(default) = default</li> |
| <li>round(row_sparse) = row_sparse</li> |
| </ul> |
| </div></blockquote> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L425</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.rsqrt"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">rsqrt</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.rsqrt" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns element-wise inverse square-root value of the input.</p> |
| <div class="math"> |
| \[rsqrt(x) = 1/\sqrt{x}\]</div> |
| <p>Example:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">rsqrt</span><span class="p">([</span><span class="mi">4</span><span class="p">,</span><span class="mi">9</span><span class="p">,</span><span class="mi">16</span><span class="p">])</span> <span class="o">=</span> <span class="p">[</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.33333334</span><span class="p">,</span> <span class="mf">0.25</span><span class="p">]</span> |
| </pre></div> |
| </div> |
| <p>The storage type of <code class="docutils literal"><span class="pre">rsqrt</span></code> output is always dense</p> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L581</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.sigmoid"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">sigmoid</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.sigmoid" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Computes sigmoid of x element-wise.</p> |
| <div class="math"> |
| \[y = 1 / (1 + exp(-x))\]</div> |
| <p>The storage type of <code class="docutils literal"><span class="pre">sigmoid</span></code> output is always dense</p> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L104</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.sign"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">sign</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.sign" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns element-wise sign of the input.</p> |
| <p>Example:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">sign</span><span class="p">([</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span> <span class="o">=</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span> |
| </pre></div> |
| </div> |
| <p>The storage type of <code class="docutils literal"><span class="pre">sign</span></code> output depends upon the input storage type:</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li>sign(default) = default</li> |
| <li>sign(row_sparse) = row_sparse</li> |
| </ul> |
| </div></blockquote> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L406</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.sin"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">sin</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.sin" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Computes the element-wise sine of the input array.</p> |
| <p>The input should be in radians (<span class="math">\(2\pi\)</span> rad equals 360 degrees).</p> |
| <div class="math"> |
| \[sin([0, \pi/4, \pi/2]) = [0, 0.707, 1]\]</div> |
| <p>The storage type of <code class="docutils literal"><span class="pre">sin</span></code> output depends upon the input storage type:</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li>sin(default) = default</li> |
| <li>sin(row_sparse) = row_sparse</li> |
| </ul> |
| </div></blockquote> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_trig.cc:L46</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.sinh"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">sinh</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.sinh" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns the hyperbolic sine of the input array, computed element-wise.</p> |
| <div class="math"> |
| \[sinh(x) = 0.5\times(exp(x) - exp(-x))\]</div> |
| <p>The storage type of <code class="docutils literal"><span class="pre">sinh</span></code> output depends upon the input storage type:</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li>sinh(default) = default</li> |
| <li>sinh(row_sparse) = row_sparse</li> |
| </ul> |
| </div></blockquote> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_trig.cc:L201</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.slice"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">slice</code><span class="sig-paren">(</span><em>data=None</em>, <em>begin=_Null</em>, <em>end=_Null</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.slice" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Slices a contiguous region of the array.</p> |
| <div class="admonition note"> |
| <p class="first admonition-title">Note</p> |
| <p class="last"><code class="docutils literal"><span class="pre">crop</span></code> is deprecated. Use <code class="docutils literal"><span class="pre">slice</span></code> instead.</p> |
| </div> |
| <p>This function returns a sliced continuous region of the array between the indices given |
| by <cite>begin</cite> and <cite>end</cite>.</p> |
| <p>For an input array of <cite>n</cite> dimensions, slice operation with <code class="docutils literal"><span class="pre">begin=(b_0,</span> <span class="pre">b_1...b_n-1)</span></code> indices |
| and <code class="docutils literal"><span class="pre">end=(e_1,</span> <span class="pre">e_2,</span> <span class="pre">...</span> <span class="pre">e_n)</span></code> indices will result in an array with the shape |
| <code class="docutils literal"><span class="pre">(e_1-b_0,</span> <span class="pre">...,</span> <span class="pre">e_n-b_n-1)</span></code>.</p> |
| <p>The resulting array’s <em>k</em>-th dimension contains elements |
| from the <em>k</em>-th dimension of the input array with the open range <code class="docutils literal"><span class="pre">[b_k,</span> <span class="pre">e_k)</span></code>.</p> |
| <p>For an input array of non-default storage type(e.g. <cite>csr</cite> or <cite>row_sparse</cite>), it only supports |
| slicing on the first dimension.</p> |
| <p>Example:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">x</span> <span class="o">=</span> <span class="p">[[</span> <span class="mf">1.</span><span class="p">,</span> <span class="mf">2.</span><span class="p">,</span> <span class="mf">3.</span><span class="p">,</span> <span class="mf">4.</span><span class="p">],</span> |
| <span class="p">[</span> <span class="mf">5.</span><span class="p">,</span> <span class="mf">6.</span><span class="p">,</span> <span class="mf">7.</span><span class="p">,</span> <span class="mf">8.</span><span class="p">],</span> |
| <span class="p">[</span> <span class="mf">9.</span><span class="p">,</span> <span class="mf">10.</span><span class="p">,</span> <span class="mf">11.</span><span class="p">,</span> <span class="mf">12.</span><span class="p">]]</span> |
| |
| <span class="nb">slice</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">begin</span><span class="o">=</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">),</span> <span class="n">end</span><span class="o">=</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">4</span><span class="p">))</span> <span class="o">=</span> <span class="p">[[</span> <span class="mf">2.</span><span class="p">,</span> <span class="mf">3.</span><span class="p">,</span> <span class="mf">4.</span><span class="p">],</span> |
| <span class="p">[</span> <span class="mf">6.</span><span class="p">,</span> <span class="mf">7.</span><span class="p">,</span> <span class="mf">8.</span><span class="p">]]</span> |
| </pre></div> |
| </div> |
| <p>Defined in src/operator/tensor/matrix_op.cc:L278</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – Source input</li> |
| <li><strong>begin</strong> (<em>Shape(tuple), required</em>) – starting indices for the slice operation, supports negative indices.</li> |
| <li><strong>end</strong> (<em>Shape(tuple), required</em>) – ending indices for the slice operation, supports negative indices.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.sqrt"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">sqrt</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.sqrt" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns element-wise square-root value of the input.</p> |
| <div class="math"> |
| \[\textrm{sqrt}(x) = \sqrt{x}\]</div> |
| <p>Example:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">sqrt</span><span class="p">([</span><span class="mi">4</span><span class="p">,</span> <span class="mi">9</span><span class="p">,</span> <span class="mi">16</span><span class="p">])</span> <span class="o">=</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">]</span> |
| </pre></div> |
| </div> |
| <p>The storage type of <code class="docutils literal"><span class="pre">sqrt</span></code> output depends upon the input storage type:</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li>sqrt(default) = default</li> |
| <li>sqrt(row_sparse) = row_sparse</li> |
| </ul> |
| </div></blockquote> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L561</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.square"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">square</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.square" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns element-wise squared value of the input.</p> |
| <div class="math"> |
| \[square(x) = x^2\]</div> |
| <p>Example:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">square</span><span class="p">([</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">])</span> <span class="o">=</span> <span class="p">[</span><span class="mi">4</span><span class="p">,</span> <span class="mi">9</span><span class="p">,</span> <span class="mi">16</span><span class="p">]</span> |
| </pre></div> |
| </div> |
| <p>The storage type of <code class="docutils literal"><span class="pre">square</span></code> output depends upon the input storage type:</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li>square(default) = default</li> |
| <li>square(row_sparse) = row_sparse</li> |
| <li>square(csr) = csr</li> |
| </ul> |
| </div></blockquote> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L538</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.stop_gradient"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">stop_gradient</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.stop_gradient" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Stops gradient computation.</p> |
| <p>Stops the accumulated gradient of the inputs from flowing through this operator |
| in the backward direction. In other words, this operator prevents the contribution |
| of its inputs to be taken into account for computing gradients.</p> |
| <p>Example:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span>v1 = [1, 2] |
| v2 = [0, 1] |
| a = Variable('a') |
| b = Variable('b') |
| b_stop_grad = stop_gradient(3 * b) |
| loss = MakeLoss(b_stop_grad + a) |
| |
| executor = loss.simple_bind(ctx=cpu(), a=(1,2), b=(1,2)) |
| executor.forward(is_train=True, a=v1, b=v2) |
| executor.outputs |
| [ 1. 5.] |
| |
| executor.backward() |
| executor.grad_arrays |
| [ 0. 0.] |
| [ 1. 1.] |
| </pre></div> |
| </div> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L168</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.sum"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">sum</code><span class="sig-paren">(</span><em>data=None</em>, <em>axis=_Null</em>, <em>keepdims=_Null</em>, <em>exclude=_Null</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.sum" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Computes the sum of array elements over given axes.</p> |
| <div class="admonition note"> |
| <p class="first admonition-title">Note</p> |
| <p class="last"><cite>sum</cite> and <cite>sum_axis</cite> are equivalent. |
| For ndarray of csr storage type summation along axis 0 and axis 1 is supported. |
| Setting keepdims or exclude to True will cause a fallback to dense operator.</p> |
| </div> |
| <p>Example:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span>data = [[[1,2],[2,3],[1,3]], |
| [[1,4],[4,3],[5,2]], |
| [[7,1],[7,2],[7,3]]] |
| |
| sum(data, axis=1) |
| [[ 4. 8.] |
| [ 10. 9.] |
| [ 21. 6.]] |
| |
| sum(data, axis=[1,2]) |
| [ 12. 19. 27.] |
| |
| data = [[1,2,0], |
| [3,0,1], |
| [4,1,0]] |
| |
| csr = cast_storage(data, 'csr') |
| |
| sum(csr, axis=0) |
| [ 8. 2. 2.] |
| |
| sum(csr, axis=1) |
| [ 3. 4. 5.] |
| </pre></div> |
| </div> |
| <p>Defined in src/operator/tensor/broadcast_reduce_op_value.cc:L84</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input</li> |
| <li><strong>axis</strong> (<em>Shape(tuple), optional, default=[]</em>) – <p>The axis or axes along which to perform the reduction.</p> |
| <p>The default, <cite>axis=()</cite>, will compute over all elements into a |
| scalar array with shape <cite>(1,)</cite>.</p> |
| <p>If <cite>axis</cite> is int, a reduction is performed on a particular axis.</p> |
| <p>If <cite>axis</cite> is a tuple of ints, a reduction is performed on all the axes |
| specified in the tuple.</p> |
| <p>If <cite>exclude</cite> is true, reduction will be performed on the axes that are |
| NOT in axis instead.</p> |
| <p>Negative values means indexing from right to left.</p> |
| </li> |
| <li><strong>keepdims</strong> (<em>boolean, optional, default=0</em>) – If this is set to <cite>True</cite>, the reduced axes are left in the result as dimension with size one.</li> |
| <li><strong>exclude</strong> (<em>boolean, optional, default=0</em>) – Whether to perform reduction on axis that are NOT in axis instead.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.tan"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">tan</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.tan" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Computes the element-wise tangent of the input array.</p> |
| <p>The input should be in radians (<span class="math">\(2\pi\)</span> rad equals 360 degrees).</p> |
| <div class="math"> |
| \[tan([0, \pi/4, \pi/2]) = [0, 1, -inf]\]</div> |
| <p>The storage type of <code class="docutils literal"><span class="pre">tan</span></code> output depends upon the input storage type:</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li>tan(default) = default</li> |
| <li>tan(row_sparse) = row_sparse</li> |
| </ul> |
| </div></blockquote> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_trig.cc:L83</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.tanh"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">tanh</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.tanh" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns the hyperbolic tangent of the input array, computed element-wise.</p> |
| <div class="math"> |
| \[tanh(x) = sinh(x) / cosh(x)\]</div> |
| <p>The storage type of <code class="docutils literal"><span class="pre">tanh</span></code> output depends upon the input storage type:</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li>tanh(default) = default</li> |
| <li>tanh(row_sparse) = row_sparse</li> |
| </ul> |
| </div></blockquote> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_trig.cc:L234</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.trunc"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">trunc</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.trunc" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Return the element-wise truncated value of the input.</p> |
| <p>The truncated value of the scalar x is the nearest integer i which is closer to |
| zero than x is. In short, the fractional part of the signed number x is discarded.</p> |
| <p>Example:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">trunc</span><span class="p">([</span><span class="o">-</span><span class="mf">2.1</span><span class="p">,</span> <span class="o">-</span><span class="mf">1.9</span><span class="p">,</span> <span class="mf">1.5</span><span class="p">,</span> <span class="mf">1.9</span><span class="p">,</span> <span class="mf">2.1</span><span class="p">])</span> <span class="o">=</span> <span class="p">[</span><span class="o">-</span><span class="mf">2.</span><span class="p">,</span> <span class="o">-</span><span class="mf">1.</span><span class="p">,</span> <span class="mf">1.</span><span class="p">,</span> <span class="mf">1.</span><span class="p">,</span> <span class="mf">2.</span><span class="p">]</span> |
| </pre></div> |
| </div> |
| <p>The storage type of <code class="docutils literal"><span class="pre">trunc</span></code> output depends upon the input storage type:</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li>trunc(default) = default</li> |
| <li>trunc(row_sparse) = row_sparse</li> |
| </ul> |
| </div></blockquote> |
| <p>Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L501</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input array.</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.zeros_like"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">zeros_like</code><span class="sig-paren">(</span><em>data=None</em>, <em>out=None</em>, <em>name=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.zeros_like" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Return an array of zeros with the same shape and type |
| as the input array.</p> |
| <p>The storage type of <code class="docutils literal"><span class="pre">zeros_like</span></code> output depends on the storage type of the input</p> |
| <ul class="simple"> |
| <li>zeros_like(row_sparse) = row_sparse</li> |
| <li>zeros_like(csr) = csr</li> |
| <li>zeros_like(default) = default</li> |
| </ul> |
| <p>Examples:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">x</span> <span class="o">=</span> <span class="p">[[</span> <span class="mf">1.</span><span class="p">,</span> <span class="mf">1.</span><span class="p">,</span> <span class="mf">1.</span><span class="p">],</span> |
| <span class="p">[</span> <span class="mf">1.</span><span class="p">,</span> <span class="mf">1.</span><span class="p">,</span> <span class="mf">1.</span><span class="p">]]</span> |
| |
| <span class="n">zeros_like</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">=</span> <span class="p">[[</span> <span class="mf">0.</span><span class="p">,</span> <span class="mf">0.</span><span class="p">,</span> <span class="mf">0.</span><span class="p">],</span> |
| <span class="p">[</span> <span class="mf">0.</span><span class="p">,</span> <span class="mf">0.</span><span class="p">,</span> <span class="mf">0.</span><span class="p">]]</span> |
| </pre></div> |
| </div> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The input</li> |
| <li><strong>out</strong> (<em>NDArray, optional</em>) – The output NDArray to hold the result.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>out</strong> – |
| The output of this function.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">NDArray or list of NDArrays</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <span class="target" id="module-mxnet.ndarray.sparse"></span><p>Sparse NDArray API of MXNet.</p> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.zeros"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">zeros</code><span class="sig-paren">(</span><em>stype</em>, <em>shape</em>, <em>ctx=None</em>, <em>dtype=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.zeros" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Return a new array of given shape and type, filled with zeros.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>stype</strong> (<em>string</em>) – The storage type of the empty array, such as ‘row_sparse’, ‘csr’, etc</li> |
| <li><strong>shape</strong> (<em>int or tuple of int</em>) – The shape of the empty array</li> |
| <li><strong>ctx</strong> (<em>Context, optional</em>) – An optional device context (default is the current default context)</li> |
| <li><strong>dtype</strong> (<em>str or numpy.dtype, optional</em>) – An optional value type (default is <cite>float32</cite>)</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">A created array</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">RowSparseNDArray or CSRNDArray</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">sparse</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="s1">'csr'</span><span class="p">,</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">))</span> |
| <span class="go"><CSRNDArray 1x2 @cpu(0)></span> |
| <span class="gp">>>> </span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">sparse</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="s1">'row_sparse'</span><span class="p">,</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">),</span> <span class="n">ctx</span><span class="o">=</span><span class="n">mx</span><span class="o">.</span><span class="n">cpu</span><span class="p">(),</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">'float16'</span><span class="p">)</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">array([[ 0., 0.]], dtype=float16)</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.empty"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">empty</code><span class="sig-paren">(</span><em>stype</em>, <em>shape</em>, <em>ctx=None</em>, <em>dtype=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.empty" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns a new array of given shape and type, without initializing entries.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>stype</strong> (<em>string</em>) – The storage type of the empty array, such as ‘row_sparse’, ‘csr’, etc</li> |
| <li><strong>shape</strong> (<em>int or tuple of int</em>) – The shape of the empty array.</li> |
| <li><strong>ctx</strong> (<em>Context, optional</em>) – An optional device context (default is the current default context).</li> |
| <li><strong>dtype</strong> (<em>str or numpy.dtype, optional</em>) – An optional value type (default is <cite>float32</cite>).</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">A created array.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CSRNDArray or RowSparseNDArray</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.sparse.array"> |
| <code class="descclassname">mxnet.ndarray.sparse.</code><code class="descname">array</code><span class="sig-paren">(</span><em>source_array</em>, <em>ctx=None</em>, <em>dtype=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.sparse.array" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Creates a sparse array from any object exposing the array interface.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>source_array</strong> (<em>RowSparseNDArray, CSRNDArray or scipy.sparse.csr.csr_matrix</em>) – The source sparse array</li> |
| <li><strong>ctx</strong> (<em>Context, optional</em>) – The default context is <code class="docutils literal"><span class="pre">source_array.context</span></code> if <code class="docutils literal"><span class="pre">source_array</span></code> is an NDArray. The current default context otherwise.</li> |
| <li><strong>dtype</strong> (<em>str or numpy.dtype, optional</em>) – The data type of the output array. The default dtype is <code class="docutils literal"><span class="pre">source_array.dtype</span></code> |
| if <cite>source_array</cite> is an <cite>NDArray</cite>, <cite>numpy.ndarray</cite> or <cite>scipy.sparse.csr.csr_matrix</cite>, <cite>float32</cite> otherwise.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">An array with the same contents as the <cite>source_array</cite>.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">RowSparseNDArray or CSRNDArray</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">scipy.sparse</span> <span class="kn">as</span> <span class="nn">spsp</span> |
| <span class="gp">>>> </span><span class="n">csr</span> <span class="o">=</span> <span class="n">spsp</span><span class="o">.</span><span class="n">csr_matrix</span><span class="p">((</span><span class="mi">2</span><span class="p">,</span> <span class="mi">100</span><span class="p">))</span> |
| <span class="gp">>>> </span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">sparse</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">csr</span><span class="p">)</span> |
| <span class="go"><CSRNDArray 2x100 @cpu(0)></span> |
| <span class="gp">>>> </span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">sparse</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">sparse</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="s1">'csr'</span><span class="p">,</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">)))</span> |
| <span class="go"><CSRNDArray 3x2 @cpu(0)></span> |
| <span class="gp">>>> </span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">sparse</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">sparse</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="s1">'row_sparse'</span><span class="p">,</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">)))</span> |
| <span class="go"><RowSparseNDArray 3x2 @cpu(0)></span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <span class="target" id="module-mxnet.ndarray"></span><p>NDArray API of MXNet.</p> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.load"> |
| <code class="descclassname">mxnet.ndarray.</code><code class="descname">load</code><span class="sig-paren">(</span><em>fname</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.load" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Loads an array from file.</p> |
| <p>See more details in <code class="docutils literal"><span class="pre">save</span></code>.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>fname</strong> (<em>str</em>) – The filename.</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Loaded data.</td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">list of NDArray, RowSparseNDArray or CSRNDArray, or dict of str to NDArray, RowSparseNDArray or CSRNDArray</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.ndarray.save"> |
| <code class="descclassname">mxnet.ndarray.</code><code class="descname">save</code><span class="sig-paren">(</span><em>fname</em>, <em>data</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.ndarray.save" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Saves a list of arrays or a dict of str->array to file.</p> |
| <p>Examples of filenames:</p> |
| <ul class="simple"> |
| <li><code class="docutils literal"><span class="pre">/path/to/file</span></code></li> |
| <li><code class="docutils literal"><span class="pre">s3://my-bucket/path/to/file</span></code> (if compiled with AWS S3 supports)</li> |
| <li><code class="docutils literal"><span class="pre">hdfs://path/to/file</span></code> (if compiled with HDFS supports)</li> |
| </ul> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple"> |
| <li><strong>fname</strong> (<em>str</em>) – The filename.</li> |
| <li><strong>data</strong> (<em>NDArray, RowSparseNDArray or CSRNDArray, or list of NDArray, RowSparseNDArray or CSRNDArray, or dict of str to NDArray, RowSparseNDArray or CSRNDArray</em>) – The data to save.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">))</span> |
| <span class="gp">>>> </span><span class="n">y</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">ones</span><span class="p">((</span><span class="mi">1</span><span class="p">,</span><span class="mi">4</span><span class="p">))</span> |
| <span class="gp">>>> </span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="s1">'my_list'</span><span class="p">,</span> <span class="p">[</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">])</span> |
| <span class="gp">>>> </span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="s1">'my_dict'</span><span class="p">,</span> <span class="p">{</span><span class="s1">'x'</span><span class="p">:</span><span class="n">x</span><span class="p">,</span> <span class="s1">'y'</span><span class="p">:</span><span class="n">y</span><span class="p">})</span> |
| <span class="gp">>>> </span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="s1">'my_list'</span><span class="p">)</span> |
| <span class="go">[<NDArray 2x3 @cpu(0)>, <NDArray 1x4 @cpu(0)>]</span> |
| <span class="gp">>>> </span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="s1">'my_dict'</span><span class="p">)</span> |
| <span class="go">{'y': <NDArray 1x4 @cpu(0)>, 'x': <NDArray 2x3 @cpu(0)>}</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <script>auto_index("api-reference");</script></div> |
| </div> |
| </div> |
| </div> |
| <div aria-label="main navigation" class="sphinxsidebar rightsidebar" role="navigation"> |
| <div class="sphinxsidebarwrapper"> |
| <h3><a href="../../../index.html">Table Of Contents</a></h3> |
| <ul> |
| <li><a class="reference internal" href="#">Sparse NDArray API</a><ul> |
| <li><a class="reference internal" href="#overview">Overview</a></li> |
| <li><a class="reference internal" href="#the-csrndarray-class">The <code class="docutils literal"><span class="pre">CSRNDArray</span></code> class</a><ul> |
| <li><a class="reference internal" href="#array-attributes">Array attributes</a></li> |
| <li><a class="reference internal" href="#array-conversion">Array conversion</a></li> |
| <li><a class="reference internal" href="#array-creation">Array creation</a></li> |
| <li><a class="reference internal" href="#indexing">Indexing</a></li> |
| <li><a class="reference internal" href="#lazy-evaluation">Lazy evaluation</a></li> |
| </ul> |
| </li> |
| <li><a class="reference internal" href="#the-rowsparsendarray-class">The <code class="docutils literal"><span class="pre">RowSparseNDArray</span></code> class</a><ul> |
| <li><a class="reference internal" href="#array-attributes">Array attributes</a></li> |
| <li><a class="reference internal" href="#array-conversion">Array conversion</a></li> |
| <li><a class="reference internal" href="#array-creation">Array creation</a></li> |
| <li><a class="reference internal" href="#array-rounding">Array rounding</a></li> |
| <li><a class="reference internal" href="#indexing">Indexing</a></li> |
| <li><a class="reference internal" href="#lazy-evaluation">Lazy evaluation</a></li> |
| </ul> |
| </li> |
| <li><a class="reference internal" href="#array-creation-routines">Array creation routines</a></li> |
| <li><a class="reference internal" href="#array-manipulation-routines">Array manipulation routines</a><ul> |
| <li><a class="reference internal" href="#changing-array-storage-type">Changing array storage type</a></li> |
| <li><a class="reference internal" href="#indexing-routines">Indexing routines</a></li> |
| </ul> |
| </li> |
| <li><a class="reference internal" href="#mathematical-functions">Mathematical functions</a><ul> |
| <li><a class="reference internal" href="#arithmetic-operations">Arithmetic operations</a></li> |
| <li><a class="reference internal" href="#trigonometric-functions">Trigonometric functions</a></li> |
| <li><a class="reference internal" href="#hyperbolic-functions">Hyperbolic functions</a></li> |
| <li><a class="reference internal" href="#rounding">Rounding</a></li> |
| <li><a class="reference internal" href="#exponents-and-logarithms">Exponents and logarithms</a></li> |
| <li><a class="reference internal" href="#powers">Powers</a></li> |
| <li><a class="reference internal" href="#miscellaneous">Miscellaneous</a></li> |
| <li><a class="reference internal" href="#more">More</a></li> |
| </ul> |
| </li> |
| <li><a class="reference internal" href="#api-reference">API Reference</a></li> |
| </ul> |
| </li> |
| </ul> |
| </div> |
| </div> |
| </div><div class="footer"> |
| <div class="section-disclaimer"> |
| <div class="container"> |
| <div> |
| <img height="60" src="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/image/apache_incubator_logo.png"/> |
| <p> |
| Apache MXNet is an effort undergoing incubation at The Apache Software Foundation (ASF), <strong>sponsored by the <i>Apache Incubator</i></strong>. Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects. While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF. |
| </p> |
| <p> |
| "Copyright © 2017, The Apache Software Foundation |
| Apache MXNet, MXNet, Apache, the Apache feather, and the Apache MXNet project logo are either registered trademarks or trademarks of the Apache Software Foundation." |
| </p> |
| </div> |
| </div> |
| </div> |
| </div> <!-- pagename != index --> |
| </div> |
| <script crossorigin="anonymous" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> |
| <script src="../../../_static/js/sidebar.js" type="text/javascript"></script> |
| <script src="../../../_static/js/search.js" type="text/javascript"></script> |
| <script src="../../../_static/js/navbar.js" type="text/javascript"></script> |
| <script src="../../../_static/js/clipboard.min.js" type="text/javascript"></script> |
| <script src="../../../_static/js/copycode.js" type="text/javascript"></script> |
| <script src="../../../_static/js/page.js" type="text/javascript"></script> |
| <script type="text/javascript"> |
| $('body').ready(function () { |
| $('body').css('visibility', 'visible'); |
| }); |
| </script> |
| </body> |
| </html> |