I would like to convert a mydata.csv file to a Numpy array.
I have a matrix representation mydata.csv file
(The matrix is 14*79 with signed values without any header name.)
-0.094391 -0.086641 0.31659 0.66066 -0.33076 0.02751 …
-0.26169 -0.022418 0.47564 0.39925 -0.22232 0.16129 …
-0.33073 0.026102 0.62409 -0.098799 -0.086641 0.31832 …
-0.22134 0.15488 0.69289 -0.26515 -0.021011 0.47096 …
I thought this code would work for this case.
import numpy as np
data = np.genfromtxt('mydata.csv', dtype=float, delimiter=',', names=False)
but it did not work.
and I would like to have final Numpy data shape as data.shape = (14, 79)
My error message looks like this though..
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-26-060012d7c568> in <module>
1 import numpy as np
2
----> 3 data = np.genfromtxt('output.csv', dtype=float, delimiter=',', names=False)
~\Anaconda3\envs\tensorflow\lib\site-packages\numpy\lib\npyio.py in genfromtxt(fname, dtype, comments, delimiter, skip_header, skip_footer, converters, missing_values, filling_values, usecols, names, excludelist, deletechars, replace_space, autostrip, case_sensitive, defaultfmt, unpack, usemask, loose, invalid_raise, max_rows, encoding)
1810 deletechars=deletechars,
1811 case_sensitive=case_sensitive,
-> 1812 replace_space=replace_space)
1813 # Make sure the names is a list (for 2.5)
1814 if names is not None:
~\Anaconda3\envs\tensorflow\lib\site-packages\numpy\lib\_iotools.py in easy_dtype(ndtype, names, defaultfmt, **validationargs)
934 # Simple dtype: repeat to match the nb of names
935 if nbtypes == 0:
--> 936 formats = tuple([ndtype.type] * len(names))
937 names = validate(names, defaultfmt=defaultfmt)
938 ndtype = np.dtype(list(zip(names, formats)))
TypeError: object of type 'bool' has no len()