I have a csv file that looks like below
[0.037621960043907166, 0.04622473940253258, 0.9161532521247864]
[0.030109738931059837, 0.03261643648147583, 0.9372738003730774]
[0.030109738931059837, 0.03261643648147583, 0.9372738003730774]
I need to convert this to numpy array. If I use below code
data = genfromtxt(file, delimiter=',', encoding="utf8")
I get nan in the output.
If I do this
np.genfromtxt (file, encoding=None, dtype = None)
It fails to remove the starting and ending brackets of the list and outputs like
array = ([['[0.037621960043907166,', '0.04622473940253258,',
'0.9161532521247864]'],
['[0.030109738931059837,', '0.03261643648147583,',
'0.9372738003730774]'],
['[0.030109738931059837,', '0.03261643648147583,',
'0.9372738003730774]']], dtype='<U22')
the expected output is
array = ([['0.037621960043907166,', '0.04622473940253258,',
'0.9161532521247864'],
['0.030109738931059837,', '0.03261643648147583,',
'0.9372738003730774'],
['0.030109738931059837,', '0.03261643648147583,',
'0.9372738003730774']], dtype='<U22')
How can I get the expected output? Seems I need to remove the brackets 1st before applying the numpy operations. Any suggestion?