I have a multiple .npy files and want to have them in one n-dimentional np.array
np.load(file) has shape (n, 3). There are m files, so result shape should be (m, n, 3)
Now i have this:
np.array([np.load(file) for file in h_files])
output:
array([array([[ 3.40040e 00, -1.48372e-02, -6.52934e-01],
[ 3.37660e 00, -1.53226e-02, -5.28748e-01],
[ 3.36828e 00, -1.58727e-02, -4.08290e-01],
...,
[ 3.35563e 00, -2.34267e-03, 2.89650e-01],
[ 3.35869e 00, -2.93101e-03, 1.74017e-01],
[ 3.36274e 00, -3.52146e-03, 5.80292e-02]], dtype=float32),
array([[ 3.40534 , -0.00772648, -0.653887 ],
[ 3.37169 , -0.0082386 , -0.527966 ],
[ 3.36334 , -0.00880522, -0.407682 ],
...,
What result i would like to have:
array( [[[ 3.40040e 00, -1.48372e-02, -6.52934e-01],
[ 3.37660e 00, -1.53226e-02, -5.28748e-01],
[ 3.36828e 00, -1.58727e-02, -4.08290e-01],
...,
[ 3.35563e 00, -2.34267e-03, 2.89650e-01],
[ 3.35869e 00, -2.93101e-03, 1.74017e-01],
[ 3.36274e 00, -3.52146e-03, 5.80292e-02]],
[[ 3.40534 , -0.00772648, -0.653887 ],
[ 3.37169 , -0.0082386 , -0.527966 ],
[ 3.36334 , -0.00880522, -0.407682 ],
...,
CodePudding user response:
Check out the concatenate method: https://numpy.org/doc/stable/reference/generated/numpy.concatenate.html
CodePudding user response:
I have not checked it, but you could try the following:
np.array([np.load(file).tolist() for file in h_files])