Skip to content

Instantly share code, notes, and snippets.

@yamaguchiyuto
Created November 13, 2016 13:33
Show Gist options
  • Save yamaguchiyuto/6cf39c77df3bf44fe6ed5aaf98c343cc to your computer and use it in GitHub Desktop.
Save yamaguchiyuto/6cf39c77df3bf44fe6ed5aaf98c343cc to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"\"\"\" 2x3行列Xと、4x5行列Yを作る \"\"\"\n",
"\n",
"I = 2\n",
"J = 3\n",
"K = 4\n",
"L = 5\n",
"X = np.random.random(size=(I,J))\n",
"Y = np.random.random(size=(K,L))"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"(8, 15)"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\"\"\" クロネッカー積を計算 \"\"\"\n",
"\"\"\" 8x15行列になる \"\"\"\n",
"X_kron_Y = np.kron(X,Y)\n",
"X_kron_Y.shape"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.0\n"
]
}
],
"source": [
"\"\"\" クロネッカー積のインデキシング \"\"\"\n",
"\"\"\" インデックスが0から始まるので式とちょっと違う \"\"\"\n",
"i = 0\n",
"j = 2\n",
"k = 1\n",
"l = 3\n",
"print X[i,j]*Y[k,l] - X_kron_Y[i*K+k,j*L+l]"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment