{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "d9b883c6",
            "cell_type": "markdown",
            "source": "<div class='alert alert-warning'>\n\nSciPy's interactive examples with Jupyterlite are experimental and may not always work as expected. Execution of cells containing imports may result in large downloads (up to 60MB of content for the first import from SciPy). Load times when importing from SciPy may take roughly 10-20 seconds. If you notice any problems, feel free to open an [issue](https://github.com/scipy/scipy/issues/new/choose).\n\n</div>",
            "metadata": {}
        },
        {
            "id": "3c3816d4",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import numpy as np\nimport scipy.sparse\nA = scipy.sparse.coo_array([[[2, 3], [0, 0]], [[0, 1], [0, 5]]])\nA.shape",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "(2, 2, 2)"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "97a0d22b",
            "cell_type": "markdown",
            "source": "Integer axes N are shorthand for (range(-N, 0), range(0, N)):\n",
            "metadata": {}
        },
        {
            "id": "96102b29",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "A.tensordot(A, axes=1).toarray()",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[[[ 4,  9],\n         [ 0, 15]],\n<BLANKLINE>\n        [[ 0,  0],\n         [ 0,  0]]],\n<BLANKLINE>\n<BLANKLINE>\n       [[[ 0,  1],\n         [ 0,  5]],\n<BLANKLINE>\n        [[ 0,  5],\n         [ 0, 25]]]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "e82882cc",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "A.tensordot(A, axes=2).toarray()",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[ 4,  6],\n       [ 0, 25]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "3524ca8c",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "A.tensordot(A, axes=3)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array(39)"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "90ffa92f",
            "cell_type": "markdown",
            "source": "Using tuple for axes:\n",
            "metadata": {}
        },
        {
            "id": "33ca31a5",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "a = scipy.sparse.coo_array(np.arange(60).reshape(3,4,5))\nb = np.arange(24).reshape(4,3,2)\nc = a.tensordot(b, axes=([1,0],[0,1]))\nc.shape",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "(5, 2)"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "b65457e5",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "c",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[4400, 4730],\n       [4532, 4874],\n       [4664, 5018],\n       [4796, 5162],\n       [4928, 5306]])"
                    },
                    "execution_count": null
                }
            ]
        }
    ]
}