Python numpy: reshape list into repeating 2D array -


i'm new python , have question numpy.reshape. have 2 lists of values this:

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

and want them in separate 2d arrays, each item repeated length of original lists, this:

xx = [[0,0,0,0]      [1,1,1,1]      [2,2,2,2]      [3,3,3,3]]  yy = [[4,5,6,7]       [4,5,6,7]       [4,5,6,7]       [4,5,6,7]] 

is there way numpy.reshape, or there better method use? appreciate detailed explanation. thanks!

numpy.meshgrid you.

n.b. requested output, looks want ij indexing, not default xy

from numpy import meshgrid  x = [0,1,2,3] y = [4,5,6,7] xx,yy=meshgrid(x,y,indexing='ij')  print xx >>> [[0 0 0 0]      [1 1 1 1]      [2 2 2 2]      [3 3 3 3]]  print yy >>> [[4 5 6 7]      [4 5 6 7]      [4 5 6 7]      [4 5 6 7]] 

for reference, here's xy indexing

xx,yy=meshgrid(x,y,indexing='xy')  print xx >>> [[0 1 2 3]      [0 1 2 3]      [0 1 2 3]      [0 1 2 3]]  print yy >>> [[4 4 4 4]      [5 5 5 5]      [6 6 6 6]      [7 7 7 7]] 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -