Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I have loaded a .csv file in python with
numpy.genfromtxt
. Now it returns a 1 dimensional
numpy.ndarray
with in that array,
numpy.void
objects which are actually just arrays of integers. However I would like to convert these from type
numpy.void
to
numpy.array
. To clarify:
>>> print(train_data.shape)
(42000,)
>>> print(type(train_data[0]))
<class 'numpy.void'>
>>> print(train_data[0])
(9, 0, 0)
So here the array (9, 0, 0) which has type numpy.void
should be a numpy.array
.
How can I convert all values from train_data
to be numpy arrays?
Efficiency is also somewhat important because I am working with a lot of data.
Some more code
>>> with open('filename.csv', 'rt') as raw_training_data:
>>> train_data = numpy.genfromtxt(raw_training_data, delimiter=',', names=True, dtype=numpy.integer)
>>> print(train_data.dtype)
[('label', '<i4'), ('pixel0', '<i4'), ('pixel1', '<i4')]
>>> print(type(train_data))
<class 'numpy.ndarray'>
–
–
–
–
I know it is too late to answer this. But found a solution for a similar problem I had, thanks to the solution provided in this question.
If you can convert the train_data to list and then convert it to an numpy array, that would do the job for you.
print(np.array(train_data.tolist()).shape)
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.