Created
May 26, 2021 07:52
-
-
Save genkuroki/7f06442fc0e9b085252f7228f6aa7392 to your computer and use it in GitHub Desktop.
write and read a matrix
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
{ | |
"cells": [ | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "https://discourse.julialang.org/t/exact-numerical-logging/58766" | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "A = randn(5, 5)", | |
"execution_count": 1, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 1, | |
"data": { | |
"text/plain": "5×5 Matrix{Float64}:\n -0.240283 1.60532 -1.15529 0.260169 1.2585\n 0.423185 -0.867211 -1.2176 -0.512242 -1.04863\n 0.341219 -0.140905 -0.03313 -1.7478 -0.598576\n 0.333095 0.424912 -0.576262 -2.0013 -0.671772\n 1.95515 -0.338912 1.11586 1.74802 -0.0456715" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "string(A)", | |
"execution_count": 2, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 2, | |
"data": { | |
"text/plain": "\"[-0.2402826849352379 1.6053180905943534 -1.1552904597891978 0.26016872756648324 1.2584979744077427; 0.42318527856955884 -0.8672106347900607 -1.2175988774418558 -0.5122421299004011 -1.048628660584414; 0.3412186857086955 -0.1409045074904742 -0.03312995769217814 -1.7478019236951658 -0.598576214513245; 0.3330952595045313 0.42491234364889346 -0.5762617588060361 -2.001300594425213 -0.6717715695671819; 1.955147023461729 -0.3389123482008798 1.115860107519043 1.7480203496645637 -0.04567149678748327]\"" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "write(\"A.txt\", string(A))", | |
"execution_count": 3, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 3, | |
"data": { | |
"text/plain": "495" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "read(\"A.txt\", String)", | |
"execution_count": 4, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 4, | |
"data": { | |
"text/plain": "\"[-0.2402826849352379 1.6053180905943534 -1.1552904597891978 0.26016872756648324 1.2584979744077427; 0.42318527856955884 -0.8672106347900607 -1.2175988774418558 -0.5122421299004011 -1.048628660584414; 0.3412186857086955 -0.1409045074904742 -0.03312995769217814 -1.7478019236951658 -0.598576214513245; 0.3330952595045313 0.42491234364889346 -0.5762617588060361 -2.001300594425213 -0.6717715695671819; 1.955147023461729 -0.3389123482008798 1.115860107519043 1.7480203496645637 -0.04567149678748327]\"" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "Meta.parse(read(\"A.txt\", String))", | |
"execution_count": 5, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 5, | |
"data": { | |
"text/plain": ":([-0.2402826849352379 1.6053180905943534 -1.1552904597891978 0.26016872756648324 1.2584979744077427; 0.42318527856955884 -0.8672106347900607 -1.2175988774418558 -0.5122421299004011 -1.048628660584414; 0.3412186857086955 -0.1409045074904742 -0.03312995769217814 -1.7478019236951658 -0.598576214513245; 0.3330952595045313 0.42491234364889346 -0.5762617588060361 -2.001300594425213 -0.6717715695671819; 1.955147023461729 -0.3389123482008798 1.115860107519043 1.7480203496645637 -0.04567149678748327])" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "A_read = eval(Meta.parse(read(\"A.txt\", String)))", | |
"execution_count": 6, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 6, | |
"data": { | |
"text/plain": "5×5 Matrix{Float64}:\n -0.240283 1.60532 -1.15529 0.260169 1.2585\n 0.423185 -0.867211 -1.2176 -0.512242 -1.04863\n 0.341219 -0.140905 -0.03313 -1.7478 -0.598576\n 0.333095 0.424912 -0.576262 -2.0013 -0.671772\n 1.95515 -0.338912 1.11586 1.74802 -0.0456715" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "A_read == A", | |
"execution_count": 7, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 7, | |
"data": { | |
"text/plain": "true" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "", | |
"execution_count": null, | |
"outputs": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"name": "julia-1.7-depwarn-o3", | |
"display_name": "Julia 1.7.0-DEV depwarn -O3", | |
"language": "julia" | |
}, | |
"language_info": { | |
"file_extension": ".jl", | |
"name": "julia", | |
"mimetype": "application/julia", | |
"version": "1.7.0" | |
}, | |
"toc": { | |
"nav_menu": {}, | |
"number_sections": true, | |
"sideBar": true, | |
"skip_h1_title": false, | |
"base_numbering": 1, | |
"title_cell": "Table of Contents", | |
"title_sidebar": "Contents", | |
"toc_cell": false, | |
"toc_position": {}, | |
"toc_section_display": true, | |
"toc_window_display": false | |
}, | |
"@webio": { | |
"lastKernelId": null, | |
"lastCommId": null | |
}, | |
"gist": { | |
"id": "7f06442fc0e9b085252f7228f6aa7392", | |
"data": { | |
"description": "write and read a matrix", | |
"public": true | |
} | |
}, | |
"_draft": { | |
"nbviewer_url": "https://gist.github.com/7f06442fc0e9b085252f7228f6aa7392" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment