Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save HajimeKawahara/9e5ca5a2af99292f11eab56802b3b54f to your computer and use it in GitHub Desktop.

Select an option

Save HajimeKawahara/9e5ca5a2af99292f11eab56802b3b54f to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"id": "b4165e69-41e8-4d0f-ba91-4ae577942e65",
"metadata": {},
"outputs": [],
"source": [
"from scipy.linalg import khatri_rao as KH\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "eebca360-c7c8-4132-a1c1-c766dbe9dcb1",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[1, 4, 7],\n",
" [2, 5, 8],\n",
" [3, 6, 9]])"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"A = np.array([[1,4,7],[2,5,8],[3,6,9]])\n",
"A"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "fa4ffc09-a5ed-4933-b256-157e364d4bf0",
"metadata": {},
"outputs": [],
"source": [
"I = np.eye(3)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "e07ca187-e632-4357-abde-e179556a1a9b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[1., 0., 0., 4., 0., 0., 7., 0., 0.],\n",
" [0., 2., 0., 0., 5., 0., 0., 8., 0.],\n",
" [0., 0., 3., 0., 0., 6., 0., 0., 9.]])"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"KH(A.T,I).T "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "25666e86-a3c0-4e37-b4be-dabb3c6e6950",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment