I have a created a numpy array, each element of the array contains an array of the same shape (9,5). What I want is a 3D array.
I've tried using np.stack.
data = list(map(lambda x: getKmers(x, 9), data)) # getKmers creates a
# list of list from a pandas dataframe
data1D = np.array(data) # shape (350,)
data2D = np.stack(data1D)
data1D:
array([list([ pdbID AtomNo Type Eta Theta
0 1a9l.pdb 2.0 G 169.225 212.838
1 1a9l.pdb 3.0 G 168.439 206.785
2 1a9l.pdb 4.0 U 170.892 205.845
3 1a9l.pdb 5.0 G 164.726 225.982
4 1a9l.pdb 6.0 A 308.788 144.370
5 1a9l.pdb 7.0 C 185.211 209.363
6 1a9l.pdb 8.0 U 167.612 216.614
7 1a9l.pdb 9.0 C 168.741 219.239
8 1a9l.pdb 10.0 C 163.639 207.044, pdbID AtomNo Type Eta Theta
1 1a9l.pdb 3.0 G 168.439 206.785
2 1a9l.pdb 4.0 U 170.892 205.845
3 1a9l.pdb 5.0 G 164.726 225.982
4 1a9l.pdb 6.0 A 308.788 144.370
5 1a9l.pdb 7.0 C 185.211 209.363
6 1a9l.pdb 8.0 U 167.612 216.614
7 1a9l.pdb 9.0 C 168.741 219.239
8 1a9l.pdb 10.0 C 163.639 207.044
I get this error: cannot copy sequence with size 9 to array axis with dimension 5
I want to create a 3D Matrix, where every subarray is in the new 3D dimension. I gues the new shape would be (9,5,350)
data1D = np.array(data)
step is probably not needed.np.stack
works with a list of arrays (in fact if given an array it will just treat it like a list).np.stack(data)
should work, ifdata
really is a list of matching size arrays. – hpaulj