Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > e5ddaa4c8aef3b801d60a051db101461 > files > 1279

python-networkx-1.8.1-3.mga4.noarch.rpm



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Eigenvalues &mdash; NetworkX 1.8.1 documentation</title>
    
    <link rel="stylesheet" href="../../_static/networkx.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '1.8.1',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  false
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within NetworkX 1.8.1 documentation"
          href="../../_static/opensearch.xml"/>
    <link rel="top" title="NetworkX 1.8.1 documentation" href="../../index.html" />
    <link rel="up" title="Advanced" href="index.html" />
    <link rel="next" title="Heavy Metal Umlaut" href="heavy_metal_umlaut.html" />
    <link rel="prev" title="Advanced" href="index.html" /> 
  </head>
  <body>
<div style="color: black;background-color: white; font-size: 3.2em; text-align: left; padding: 15px 10px 10px 15px">
NetworkX
</div>

    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="heavy_metal_umlaut.html" title="Heavy Metal Umlaut"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="index.html" title="Advanced"
             accesskey="P">previous</a> |</li>
        <li><a href="http://networkx.github.com/">NetworkX Home </a> |&nbsp;</li>
        <li><a href="http://networkx.github.com/documentation.html">Documentation </a>|&nbsp;</li>
        <li><a href="http://networkx.github.com/download.html">Download </a> |&nbsp;</li>
        <li><a href="http://github.com/networkx">Developer (Github)</a></li>



          <li><a href="../index.html" >NetworkX Examples</a> &raquo;</li>
          <li><a href="index.html" accesskey="U">Advanced</a> &raquo;</li> 
      </ul>
    </div>



      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h4>Previous topic</h4>
  <p class="topless"><a href="index.html"
                        title="previous chapter">Advanced</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="heavy_metal_umlaut.html"
                        title="next chapter">Heavy Metal Umlaut</a></p>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="eigenvalues">
<span id="advanced-eigenvalues"></span><h1>Eigenvalues<a class="headerlink" href="#eigenvalues" title="Permalink to this headline">ΒΆ</a></h1>
<p>[<a class="reference external" href="../../_static/examples/eigenvalues.py">source code</a>]</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c">#!/usr/bin/env python</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Create an G{n,m} random graph and compute the eigenvalues.</span>

<span class="sd">Requires numpy or LinearAlgebra package from Numeric Python.</span>

<span class="sd">Uses optional pylab plotting to produce histogram of eigenvalues.</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="n">__author__</span> <span class="o">=</span> <span class="s">&quot;&quot;&quot;Aric Hagberg (hagberg@lanl.gov)&quot;&quot;&quot;</span>
<span class="n">__credits__</span> <span class="o">=</span> <span class="s">&quot;&quot;&quot;&quot;&quot;&quot;</span>
<span class="c">#    Copyright (C) 2004-2006 by</span>
<span class="c">#    Aric Hagberg &lt;hagberg@lanl.gov&gt;</span>
<span class="c">#    Dan Schult &lt;dschult@colgate.edu&gt;</span>
<span class="c">#    Pieter Swart &lt;swart@lanl.gov&gt;</span>
<span class="c">#    All rights reserved.</span>
<span class="c">#    BSD license.</span>

<span class="kn">from</span> <span class="nn">networkx</span> <span class="kn">import</span> <span class="o">*</span>
<span class="k">try</span><span class="p">:</span>
    <span class="kn">import</span> <span class="nn">numpy.linalg</span>
    <span class="n">eigenvalues</span><span class="o">=</span><span class="n">numpy</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">eigvals</span>
<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
    <span class="k">raise</span> <span class="ne">ImportError</span><span class="p">(</span><span class="s">&quot;numpy can not be imported.&quot;</span><span class="p">)</span>

<span class="k">try</span><span class="p">:</span>
    <span class="kn">from</span> <span class="nn">pylab</span> <span class="kn">import</span> <span class="o">*</span>
<span class="k">except</span><span class="p">:</span>
    <span class="k">pass</span>

<span class="n">n</span><span class="o">=</span><span class="mi">1000</span> <span class="c"># 1000 nodes</span>
<span class="n">m</span><span class="o">=</span><span class="mi">5000</span> <span class="c"># 5000 edges</span>

<span class="n">G</span><span class="o">=</span><span class="n">gnm_random_graph</span><span class="p">(</span><span class="n">n</span><span class="p">,</span><span class="n">m</span><span class="p">)</span>

<span class="n">L</span><span class="o">=</span><span class="n">generalized_laplacian</span><span class="p">(</span><span class="n">G</span><span class="p">)</span>
<span class="n">e</span><span class="o">=</span><span class="n">eigenvalues</span><span class="p">(</span><span class="n">L</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s">&quot;Largest eigenvalue:&quot;</span><span class="p">,</span> <span class="nb">max</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
<span class="k">print</span><span class="p">(</span><span class="s">&quot;Smallest eigenvalue:&quot;</span><span class="p">,</span> <span class="nb">min</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
<span class="c"># plot with matplotlib if we have it</span>
<span class="c"># shows &quot;semicircle&quot; distribution of eigenvalues</span>
<span class="k">try</span><span class="p">:</span>
    <span class="n">hist</span><span class="p">(</span><span class="n">e</span><span class="p">,</span><span class="n">bins</span><span class="o">=</span><span class="mi">100</span><span class="p">)</span> <span class="c"># histogram with 100 bins</span>
    <span class="n">xlim</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="c"># eigenvalues between 0 and 2</span>
    <span class="n">show</span><span class="p">()</span>
<span class="k">except</span><span class="p">:</span>
    <span class="k">pass</span>
</pre></div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="heavy_metal_umlaut.html" title="Heavy Metal Umlaut"
             >next</a> |</li>
        <li class="right" >
          <a href="index.html" title="Advanced"
             >previous</a> |</li>
        <li><a href="http://networkx.github.com/">NetworkX Home </a> |&nbsp;</li>
        <li><a href="http://networkx.github.com/documentation.html">Documentation </a>|&nbsp;</li>
        <li><a href="http://networkx.github.com/download.html">Download </a> |&nbsp;</li>
        <li><a href="http://github.com/networkx">Developer (Github)</a></li>



          <li><a href="../index.html" >NetworkX Examples</a> &raquo;</li>
          <li><a href="index.html" >Advanced</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2013, NetworkX Developers.
      Last updated on Oct 23, 2013.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
    </div>
  </body>
</html>