4

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.

2
  • I don't get this. How is this supposed to be a two-dimensional array? Commented Feb 10, 2012 at 15:12
  • I changed it to numpy.empty([x,y]). I just want to be able to store a list into say a position [a,b] Commented Feb 10, 2012 at 15:15

1 Answer 1

6

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.