Skip to content

Instantly share code, notes, and snippets.

@Hr0k
Created October 20, 2019 16:50
Show Gist options
  • Save Hr0k/ae8802965e90a196e12b2b773449b250 to your computer and use it in GitHub Desktop.
Save Hr0k/ae8802965e90a196e12b2b773449b250 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"#new_factor.dat\n",
"\n",
"# 0.11378502991970402\n",
"# 0.18244134223217345\n",
"# 0.12910302678224894\n",
"# 0.1101382051786099\n",
"# 0.13694262193756285\n",
"# 0.1342356170801441\n",
"# 0.1310174302733097\n",
"# 0.11768323960497845\n",
"# 0.1371792964087734\n",
"# 0.12023687438053227\n",
"# 0.11537224241228489\n",
"# 0.14050615108710385\n",
"# 0.0708270361521699\n",
"# 0.06860739334483085\n",
"# 0.11378522516278938\n",
"# 0.07478336530042679\n",
"# 0.12597270998905774\n",
"# 0.09706562348848446\n",
"# 0.1586132977248872\n",
"# 0.15236043436904328\n",
"# 0.16176872404683895\n",
"# 0.13933029580606687\n",
"# 0.18106238924179524\n",
"# 0.10913720855687514\n",
"# 0.1399938796473275\n",
"# 0.1366054681680272\n",
"# 0.12773431219135156"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\n",
"from array import array\n",
"from decimal import Decimal\n",
"\n",
"fp = \"new_factor.dat\" # fp means \"file pass\" "
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.1138\n",
"0.1824\n",
"0.1291\n",
"0.1101\n",
"0.1369\n",
"0.1342\n",
"0.1310\n",
"0.1177\n",
"0.1372\n",
"0.1202\n",
"0.1154\n",
"0.1405\n",
"0.0708\n",
"0.0686\n",
"0.1138\n",
"0.0748\n",
"0.1260\n",
"0.0971\n",
"0.1586\n",
"0.1524\n",
"0.1618\n",
"0.1393\n",
"0.1811\n",
"0.1091\n",
"0.1400\n",
"0.1366\n",
"0.1277\n",
"\n",
"\n",
"new_fact = array('d', [0.1138, 0.1824, 0.1291, 0.1101, 0.1369, 0.1342, 0.131, 0.1177, 0.1372, 0.1202, 0.1154, 0.1405, 0.0708, 0.0686, 0.1138, 0.0748, 0.126, 0.0971, 0.1586, 0.1524, 0.1618, 0.1393, 0.1811, 0.1091, 0.14, 0.1366, 0.1277])\n"
]
}
],
"source": [
"data = np.loadtxt(fp, comments = \"#\") \n",
"\n",
"new_fact = array('d')\n",
"\n",
"for l in data:\n",
" \n",
" value = Decimal(l)\n",
" V = value.quantize(Decimal('0.0001'))\n",
" new_fact.append(V)\n",
" \n",
" print (V)\n",
"\n",
"print (\"\\n\")\n",
"print (\"new_fact = \", new_fact )\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment