Skip to content

Instantly share code, notes, and snippets.

@farseerfc
Created March 31, 2014 08:41
Show Gist options
  • Save farseerfc/9888022 to your computer and use it in GitHub Desktop.
Save farseerfc/9888022 to your computer and use it in GitHub Desktop.
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"intergrate=sum"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"count = 0\n",
"def f(x):\n",
" global count\n",
" count+=1\n",
" print(\"Runs %d\" %count)\n",
" return [1, x, x*2, x*x]\n"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 5
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"inputs = range(100)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 6
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"list(map(intergrate, zip(*list(f(x) for x in inputs))))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Runs 1\n",
"Runs 2\n",
"Runs 3\n",
"Runs 4\n",
"Runs 5\n",
"Runs 6\n",
"Runs 7\n",
"Runs 8\n",
"Runs 9\n",
"Runs 10\n",
"Runs 11\n",
"Runs 12\n",
"Runs 13\n",
"Runs 14\n",
"Runs 15\n",
"Runs 16\n",
"Runs 17\n",
"Runs 18\n",
"Runs 19\n",
"Runs 20\n",
"Runs 21\n",
"Runs 22\n",
"Runs 23\n",
"Runs 24\n",
"Runs 25\n",
"Runs 26\n",
"Runs 27\n",
"Runs 28\n",
"Runs 29\n",
"Runs 30\n",
"Runs 31\n",
"Runs 32\n",
"Runs 33\n",
"Runs 34\n",
"Runs 35\n",
"Runs 36\n",
"Runs 37\n",
"Runs 38\n",
"Runs 39\n",
"Runs 40\n",
"Runs 41\n",
"Runs 42\n",
"Runs 43\n",
"Runs 44\n",
"Runs 45\n",
"Runs 46\n",
"Runs 47\n",
"Runs 48\n",
"Runs 49\n",
"Runs 50\n",
"Runs 51\n",
"Runs 52\n",
"Runs 53\n",
"Runs 54\n",
"Runs 55\n",
"Runs 56\n",
"Runs 57\n",
"Runs 58\n",
"Runs 59\n",
"Runs 60\n",
"Runs 61\n",
"Runs 62\n",
"Runs 63\n",
"Runs 64\n",
"Runs 65\n",
"Runs 66\n",
"Runs 67\n",
"Runs 68\n",
"Runs 69\n",
"Runs 70\n",
"Runs 71\n",
"Runs 72\n",
"Runs 73\n",
"Runs 74\n",
"Runs 75\n",
"Runs 76\n",
"Runs 77\n",
"Runs 78\n",
"Runs 79\n",
"Runs 80\n",
"Runs 81\n",
"Runs 82\n",
"Runs 83\n",
"Runs 84\n",
"Runs 85\n",
"Runs 86\n",
"Runs 87\n",
"Runs 88\n",
"Runs 89\n",
"Runs 90\n",
"Runs 91\n",
"Runs 92\n",
"Runs 93\n",
"Runs 94\n",
"Runs 95\n",
"Runs 96\n",
"Runs 97\n",
"Runs 98\n",
"Runs 99\n",
"Runs 100\n"
]
},
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 7,
"text": [
"[100, 4950, 9900, 328350]"
]
}
],
"prompt_number": 7
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 19
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment