Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i store a list within a numpy 2d array?

How can i store a list within a numpy 2d array?

import numpy  
A = numpy.empty([5,5], dtype=**?**)  

What should be the dtype for a variable list kind of thing here? or Is there a different way to implement this, which I strongly feel would be the case.

like image 782
zubinmehta Avatar asked Sep 21 '25 04:09

zubinmehta


1 Answers

I think what you want is:

>>> input = numpy.array(range(10))
>>> data = numpy.zeros((2,2), dtype=numpy.ndarray)
>>> data[1][1] = input
>>> data
    array([[0, 0],
          [0, [0 1 2 3 4 5 6 7 8 9]]], dtype=object)
like image 117
Bogdan Avatar answered Sep 22 '25 19:09

Bogdan