I have a method that returns a numpy array. What I want to do is in each iteration take this array and concatenate it into another array of arrays so that at the end of the loop I have a matrix
This is my code so far, but its crashing the program at the given line
delta_Array = np.array([0.01,0.02,0.03, 0.04, 0.05, 0.06,0.07, 0.08, 0.09, 0.10])
theta_Matrix = np.zeros(8)
t = Ridge(Xtrain, ytrain, .3) # This method returns an array of 8 elements
np.append(theta_Matrix,t, axis=0)
print delta_Array
print theta_Matrix
With this method, My current output is this
[ 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 ] # delta_Array
[ 0. 0. 0. 0. 0. 0. 0. 0.] # theta_Matrix
The output Id like should look something like this after 2 iterations. Also I do not know in advance the number of iterations the lop would go through.So any number of arrays could be produced after the method runs. But either way all arrays should form the theta_matrix:
theta_Matrix:
[[ 0.65 0.65565 0.19181 0.923 0.51561 0.846 0.6464 0.6464]
[ 0.9879 0.31213 0.68464 0.611 0.6161 0.61651 0.29858 0.1811]]
Thanks
I have a project were I need to do something very similar. You can implement dynamic resizing in your loop, but python’s list type is actually implemented as a dynamic array so you might as well take advantage of the tools that are already available to you. You can do something like this:
I should mention that if you already know the size you expect for
theta_Matrix, you’ll get the best performance by doing something like: