0

I have some 3D data in three 1D arrays, one for each of x,y,z. Where all three arrays are of equal length, but the data range is N*M. For example:

x = [1, 2, 3, 1, 2, 3]
y = [1, 1, 1, 2, 2, 2]
z = [11, 12, 13, 14, 15, 16]

I want to plot this using one of matplotlibs functions, most of which require as an input a single 2D array of size N*M, i.e:

z = [[11, 12, 13],
     [14, 15, 16]]   

I know I can write some loops in python to iterate through the three original arrays to put the data into the required N*M format, but my question is: is there a pre-existing python library or function for doing this? Possibly using something like numpy, although so far my research hasn't turned up any working solutions.

As an aside: I don't think the current title describes the problem well, so I am open to suggestions for a better title.

Matt
  • 57
  • 8

1 Answers1

0

As mentioned in the comment by @Daniel Mesejo you can use the 'reshape' routine in the 'numpy' library:

import numpy as np

z = np.array([11, 12, 13, 14, 15, 16])
# set values for number of rows (N) and columns (M), in a way that N*M = len(z)
N = 2
M = 3
new_z = np.reshape(z, (N,M))
DavidPM
  • 455
  • 4
  • 10