How to add a new row to an empty numpy array

Using standard Python arrays, I can do the following: arr = [] arr.append([1,2,3]) arr.append([4,5,6]) # arr is now [[1,2,3],[4,5,6]] However, I cannot do the same thing in numpy. For example: arr = np.array([]) arr = np.append(arr, np.array([1,2,3])) arr = np.append(arr, np.array([4,5,6])) # arr is now [1,2,3,4,5,6] I also looked into vstack, but when I use … Read more

How do I catch a numpy warning like it’s an exception (not just for testing)?

I have to make a Lagrange polynomial in Python for a project I’m doing. I’m doing a barycentric style one to avoid using an explicit for-loop as opposed to a Newton’s divided difference style one. The problem I have is that I need to catch a division by zero, but Python (or maybe numpy) just … Read more

How to split data into 3 sets (train, validation and test)?

I have a pandas dataframe and I wish to divide it to 3 separate sets. I know that using train_test_split from sklearn.cross_validation, one can divide the data in two sets (train and test). However, I couldn’t find any solution about splitting the data into three sets. Preferably, I’d like to have the indices of the … Read more