code for conversion of embed files into suitable csv format

This commit is contained in:
Anirban Biswas 2019-03-18 18:31:13 +05:30
parent 221d5bef29
commit 025c72c8dd
2 changed files with 85 additions and 0 deletions

View File

@ -0,0 +1,50 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"../../data/cora/cora.embed\n",
"(2708, 128)\n"
]
}
],
"source": [
"import func_convert as converter\n",
"\n",
"datasets = ['cora']\n",
"embed_fnames = ['cora.embed']\n",
"\n",
"for dataset in datasets:\n",
" for embed_fname in embed_fnames:\n",
" converter.conv_to_csv( dataset, embed_fname)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.15"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

View File

@ -0,0 +1,35 @@
# coding: utf-8
# In[70]:
import numpy as np
# In[ ]:
def conv_to_csv(dataset, name):
path = '../../data/'+dataset
fpath = path+'/'+name
print fpath
with open(fpath,'r') as f:
data = f.read().split('\n')
if len(data[-1]) == 0:
data.pop()
l=data[0]
l=l.split(' ')
mat2 = np.zeros((int(l[0]),int(l[1])))
for line in data[1:]:
l = line.split(' ')
l = [float(x) for x in l]
ind = int(l[0])
mat2[ind,:] = l[1:]
print('Number of data points :: %s ' % mat2.shape[0])
print('Number of data points :: %s ' % mat2.shape[1])
np.savetxt(fpath+'.csv',mat2,fmt='%.6e')