dwww Home | Show directory contents | Find package

{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Eigenvalues\n\nCreate an G{n,m} random graph and compute the eigenvalues.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\nimport networkx as nx\nimport numpy.linalg\n\nn = 1000  # 1000 nodes\nm = 5000  # 5000 edges\nG = nx.gnm_random_graph(n, m, seed=5040)  # Seed for reproducibility\n\nL = nx.normalized_laplacian_matrix(G)\ne = numpy.linalg.eigvals(L.toarray())\nprint(\"Largest eigenvalue:\", max(e))\nprint(\"Smallest eigenvalue:\", min(e))\nplt.hist(e, bins=100)  # histogram with 100 bins\nplt.xlim(0, 2)  # eigenvalues between 0 and 2\nplt.show()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.12.7"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}

Generated by dwww version 1.16 on Wed Apr 8 10:56:39 CEST 2026.