Created
July 23, 2015 19:59
-
-
Save npow/e399c9af862c41eead55 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
{ | |
"metadata": { | |
"name": "", | |
"signature": "sha256:5920b1afec8cc9b2dd87015709f32fee73ba2013a3b60b8719a831377a772a24" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"import numpy as np\n", | |
"import theano\n", | |
"import theano.tensor as T\n", | |
"\n", | |
"A = theano.shared(np.ones(1000, dtype=np.float32))\n", | |
"B = theano.shared(np.ones((1000,1), dtype=np.float32))\n", | |
"\n", | |
"def reshape():\n", | |
" global A\n", | |
" A = A.reshape((1000,1))\n", | |
" \n", | |
"def dimshuffle():\n", | |
" global A\n", | |
" A = A.dimshuffle(0, 'x')\n", | |
" \n", | |
"def newaxis():\n", | |
" global A\n", | |
" A = A[:, np.newaxis]" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 23 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"%timeit dimshuffle()\n", | |
"%timeit newaxis()\n", | |
"%timeit reshape()" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"10000 loops, best of 3: 39.9 \u00b5s per loop\n", | |
"10000 loops, best of 3: 182 \u00b5s per loop" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n", | |
"1000 loops, best of 3: 247 \u00b5s per loop" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n" | |
] | |
} | |
], | |
"prompt_number": 24 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"(A.dimshuffle(0,'x') + B).eval().shape" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 17, | |
"text": [ | |
"(1000, 1)" | |
] | |
} | |
], | |
"prompt_number": 17 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"B = theano.shared(np.ones((10,5), dtype=np.float32))\n", | |
"T.sum(B, axis=1).dimshuffle(0, 'x').eval().shape" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 20, | |
"text": [ | |
"(10, 1)" | |
] | |
} | |
], | |
"prompt_number": 20 | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment