Thomas Collett Thomas Collett - 1 year ago 88
Python Question

convert two lists into array coordinates python

In python, how do I build an array of coordinates given 2 lists of axes, such that the output array contains all the possible coordinate pairs



Code that combines them

Combined_ax1 = [1,3,4,1,3,4,1,3,4]
Combined_ax2 = [a,a,a,b,b,b,c,c,c]

I need this so I can feed combined_ax1 and combined_ax2 into a function without using multiple for loops.

Answer Source

This code would get what you require

import itertools


Combined_ax1, Combined_ax2 = zip(*itertools.product(ax1, ax2))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download