Created
September 29, 2014 18:20
-
-
Save sbchisholm/b7d17cc51d04d3420f97 to your computer and use it in GitHub Desktop.
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
{ | |
"metadata": { | |
"language": "Julia", | |
"name": "ylt" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "type YLT\n data::Array{Float64}\nend", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"ename": "LoadError", | |
"evalue": "invalid redefinition of constant YLT\nat In[7]:3", | |
"output_type": "pyerr", | |
"traceback": [ | |
"invalid redefinition of constant YLT\nat In[7]:3" | |
] | |
} | |
], | |
"prompt_number": 7 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "ylt = YLT([1.2, 2.3, 3.4, 4.5])", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 8, | |
"text": "YLT([1.2,2.3,3.4,4.5])" | |
} | |
], | |
"prompt_number": 8 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "function getindex(ylt::YLT, index::Symbol)\n if index == :gros\n return ylt.data[1:2:end]\n elseif index == :net\n return ylt.data[2:2:end]\n else\n error(\"invalid symbol: $index\")\n end \nend\n\nfunction getindex(ylt::YLT, indices::Symbol...)\n r = Array(Float64, int64(length(ylt.data)/2), length(indices))\n for (i, index) in enumerate(indices)\n if index == :gros\n r[:,i] = ylt.data[1:2:end]\n elseif index == :net\n r[:,i] = ylt.data[2:2:end]\n else\n error(\"invalid symbol: $index\")\n end\n end\n return r\nend", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 92, | |
"text": "getindex (generic function with 142 methods)" | |
} | |
], | |
"prompt_number": 92 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "ylt[:net]", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 93, | |
"text": "2-element Array{Float64,1}:\n 2.3\n 4.5" | |
} | |
], | |
"prompt_number": 93 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "ylt[:gros]", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 94, | |
"text": "2-element Array{Float64,1}:\n 1.2\n 3.4" | |
} | |
], | |
"prompt_number": 94 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "ylt[:wrong]", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"ename": "LoadError", | |
"evalue": "invalid symbol: wrong\nat In[95]:1", | |
"output_type": "pyerr", | |
"traceback": [ | |
"invalid symbol: wrong\nat In[95]:1", | |
" in error at error.jl:21", | |
" in getindex at In[92]:7" | |
] | |
} | |
], | |
"prompt_number": 95 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "ylt[:net, :gros]", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 96, | |
"text": "2x2 Array{Float64,2}:\n 2.3 1.2\n 4.5 3.4" | |
} | |
], | |
"prompt_number": 96 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "ylt.data", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 91, | |
"text": "4-element Array{Float64,1}:\n 1.2\n 2.3\n 3.4\n 4.5" | |
} | |
], | |
"prompt_number": 91 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment