Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the efficient inverse-operation of numpy.array_split?

I'm working on cross_validation to choose hyperparameters,and I split my training data into k folds.Take one folder as my validation data,the others as training data(I will do that for k times in fact).

X_train_folds = numpy.array_split(X_train,k)

The X_tran_folds will look like this:[subarray1,subarray2,.....]

The subarrays have the same number of columns.

But how to merge the k-1 subarrays into one?

like image 629
Han Qiu Avatar asked Mar 05 '16 14:03

Han Qiu


People also ask

Why is NumPy so efficient?

Because the Numpy array is densely packed in memory due to its homogeneous type, it also frees the memory faster. So overall a task executed in Numpy is around 5 to 100 times faster than the standard python list, which is a significant leap in terms of speed.

What is array_split NumPy?

Splitting NumPy Arrays Splitting is reverse operation of Joining. Joining merges multiple arrays into one and Splitting breaks one array into multiple. We use array_split() for splitting arrays, we pass it the array we want to split and the number of splits.

How do you Inverse an array in NumPy?

Inverse of a Matrix using NumPy Python provides a very easy method to calculate the inverse of a matrix. The function numpy. linalg. inv() which is available in the python NumPy module is used to compute the inverse of a matrix.

Can NumPy arrays efficiently store data?

Therefore, we can save the NumPy arrays into a native binary format that is efficient to both save and load. This is common for input data that has been prepared, such as transformed data, that will need to be used as the basis for testing a range of machine learning models in the future or running many experiments.


1 Answers

You can use numpy.concatenate() to join a sequence of arrays:

>>> import numpy as np
>>> a = np.array([0, 1])
>>> b = np.array([2, 3])
>>> np.concatenate((a, b))
array([0, 1, 2, 3])
like image 161
pp_ Avatar answered Nov 15 '22 09:11

pp_