0

I have a discretized 8-dimensional bounded space for which I want to get a grid over all possible combinations in a shape of (N,8). It should look like:

import numpy as np
myGrid = np.array([[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,2],...])

The bounds of all 8 dimensions are not equal.

1 Answer 1

1

You can use indices and moveaxis:

np.moveaxis(np.indices(<your shape>), 0, -1).reshape(-1, 8)

This will be zero-based, so add 1 to get exactly your desired output.

Sign up to request clarification or add additional context in comments.

3 Comments

your code snippet gave me something like [[0, 0, 0, ..., 2, 0, 3], [0, 4, 0, ..., 6, 0, 7], ...]. I'm not sure, if this prints me all combinations for 8 dimensions. And if, how can I adjust the size of each dimension? (Dim. 1 should be from 1 to 1000, Dim. 2 from 2 to 128, ...)
@shup You do realize that for example 8 dimensions each 128 different values would require half an exa byte of RAM and that is assuming using just one byte per coordinate? Apart from this minor technical difficulty I'm 100% positive this gives the correct result. As I said it is zero based, so you have for your shape to enter the differences of your start and end points---that is a vector of eight differences. and in the very end you have to add the vector of start points, another vector of eight values.
yes I do realize that, but luckily the majority of the dimensions are flat, so I'll get just around 1MB of RAM. And thanks a lot for your comment, now it makes sense to me!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.