I have a large list files that contain 2D numpy arrays pickled through numpy.save
. I am trying to read the first column of each file and create a new 2D array.
I currently read each column using numpy.load
with a mmap
. The 1D arrays are now in a list.
col_list = [] for f in file_list: Temp = np.load(f,mmap_mode='r') col_list.append(Temp[:,0])
How can I convert this into a 2D array?
Use reshape() Function to Transform 1d Array to 2d Array The number of components within every dimension defines the form of the array. We may add or delete parameters or adjust the number of items within every dimension by using reshaping. To modify the layout of a NumPy ndarray, we will be using the reshape() method.
reshape which is used to convert a 1-D array into a 2-D array of required dimensions (n x m). This function gives a new required shape without changing the data of the 1-D array. Parameters: array: is the given 1-D array that will be given a new shape or converted into 2-D array.
How to convert a 1d array of tuples to a 2d numpy array? Yes it is possible to convert a 1 dimensional numpy array to a 2 dimensional numpy array, by using "np. reshape()" this function we can achiev this.
You can use
numpy.stack(arrays, axis=0)
if you have an array of arrays. You can specify the axis in case you want to stack columns and not rows.
The array may be recreated:
a = np.array(a.tolist())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With