1

I want to make a 2D array of 2-tuples of fixed dimension (say 10x10).

e.g

[[(1,2), (1,2), (1,2)],
 [(1,2), (1,2), (1,2)],
 [(1,2), (1,2), (1,2)]]

There are also two ways that I'd like to generate this array:

  1. An array like the example above where every element is the same tuple
  2. An array which I populate iteratively with specific tuples (possibly starting with an empty array of fixed size and then using assignment)

How would I go about doing this? For #1 I tried using numpy.tiles:

>>> np.tile(np.array([1,2]), (3, 3))
array([[1, 2, 1, 2, 1, 2],
       [1, 2, 1, 2, 1, 2],
       [1, 2, 1, 2, 1, 2]])

But I can't seem to copy it across columns, the columns are just concatenated.

i.e instead of:

[[[1,2], [1,2], [1,2]],
 [[1,2], [1,2], [1,2]],
 [[1,2], [1,2], [1,2]]]
0

3 Answers 3

3

you can use numpy.full:

numpy.full((3, 3, 2), (1, 2))

output:

array([[[1, 2],
        [1, 2],
        [1, 2]],

       [[1, 2],
        [1, 2],
        [1, 2]],

       [[1, 2],
        [1, 2],
        [1, 2]]])
Sign up to request clarification or add additional context in comments.

Comments

0

for <1> you can generate like this

[[(1,2)] * 3]*3
# get [[(1, 2), (1, 2), (1, 2)], [(1, 2), (1, 2), (1, 2)], [(1, 2), (1, 2), (1, 2)]]

1 Comment

for <2> could you give a sample?
0

numpy.zeros((3,3,2))

I guess would work (but its not tuples its lists...)

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.