0

I'm looking to obtain the coordinates of all the 4D-hypercubes generated by using meshgrid in 4D.
The thing is that I have irregular divisions of the axes.

For example:

x = [0,1,2,3,5]

y = [0,1,2,3]

z = [0,1,2,3,4]

w = [0,1,2,3,5,6]

My idea is to

  1. Generate a 4D grid using these subdivisions.
  2. Then I'd like to obtain all of the 4D-hypercubes generated by these.
  3. Finally the 4D-coordinates for each of the resulting hypercubes.

I've tried to find a solution without success.
Could anyone give me a python solution.

moken
  • 3,227
  • 8
  • 13
  • 23

1 Answers1

0

I found a solution myself even without using Meshgrid:

import itertools
import numpy as np

x = [0,1,2,3,5]
y = [0,1,2,3]
z = [0,1,2,3,4]
w = [0,1,2,3,5,6]

pairs_x = list(zip(x[:-1],x[1:]))
pairs_y = list(zip(y[:-1],y[1:]))
pairs_z = list(zip(z[:-1],z[1:]))
pairs_w = list(zip(w[:-1],w[1:]))

count=0
for p1 in itertools.product( *([pairs_x]+[pairs_y]+[pairs_z]+[pairs_w]) ):
    print("Hyper-cube: ",count+1)
    count+=1
    for p2 in itertools.product(*p1):
        print(p2)
        
print('Total number of hypercubes: ',count)