Skip to main content
edited tags
Link
sahasrara62
  • 11.4k
  • 3
  • 35
  • 48
Source Link
david
  • 1.3k
  • 4
  • 21
  • 39

how do I initialize a 3D array with two 2D array in python?

I have two array as follows:

a=np.vstack([np.loadtxt(path, dtype='float') for path in glob.iglob(r'E:/PostDoc/720/*.txt')])
b=np.vstack([np.loadtxt(path, dtype='float') for path in glob.iglob(r'E:/PostDoc/1080/*.txt')])

the a and b are two arrays with size (640,6) now I define a 3D array as follows:

c = [[[0 for col in range(6)]for row in range(len(psnr_bitrate_1080))] for x in range(2)]

and I want to put a and b into c and for this, I use the following code:

c[:][:][0]=a
c[:][:][1]=b

but it does nothing and all values in c are still zero and it does not replace the values in c with a and b. do you know what is the problem? the rows and columns in c are lists while a and b are arrays. I try to make a 3D array with values of a and b. I do not know why it can not do correctly. please tell me how can I do this. Thanks.