Created
February 6, 2016 18:41
-
-
Save sawidis/d03556cd850f777009da to your computer and use it in GitHub Desktop.
Multiplication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"import numpy as np" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"a = np.array([\n", | |
" [\n", | |
" [6, 7, 8],\n", | |
" [9, 10, 11],\n", | |
" ],\n", | |
" [\n", | |
" [1, 2, 3],\n", | |
" [4, 5, 6]\n", | |
" ],\n", | |
" [\n", | |
" [1, 5, 10],\n", | |
" [23, 12, 11]\n", | |
" ],\n", | |
"])\n", | |
"\n", | |
"b = np.array([\n", | |
" [2, 3],\n", | |
" [4, 5],\n", | |
" [6, 7],\n", | |
"])" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 12, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"[[ 39 44 49]\n", | |
" [ 24 33 42]\n", | |
" [167 114 137]]\n" | |
] | |
} | |
], | |
"source": [ | |
"result = []\n", | |
"for c, d in zip(b, a):\n", | |
" result.append(c.dot(d))\n", | |
"result = np.array(result)\n", | |
"print(result)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 13, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"array([[ 39, 44, 49],\n", | |
" [ 24, 33, 42],\n", | |
" [167, 114, 137]])" | |
] | |
}, | |
"execution_count": 13, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"tmp = np.dot(b, a)\n", | |
"np.diagonal(tmp, axis1=0, axis2=1).T" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"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.6" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment