The thing I want to do is, I want append a set of numpy arrays one after the other while in a for loop. So whenever a new array comes, the new array will be appended to the older one. The code I have written is as follows:
def joinArray(highest_score, seq):
seq1 = np.array([])
seq2 = np.array([])
seq3 = np.array([])
seq4 = np.array([])
seq5 = np.array([])
if(highest_score == 1):
seq1 = np.concatenate((seq1,seq), axis = 1)
return(seq1)
if(highest_score == 2):
seq2 = np.concatenate((seq2,seq), axis = 1)
if(highest_score == 3):
seq3 = np.concatenate((seq3,seq), axis = 1)
if(highest_score == 4):
seq4 = np.concatenate((seq4,seq), axis = 1)
if(highest_score == 5):
seq5 = np.concatenate((seq5,seq), axis = 1)
def sequenced(dat):
for i in range(0,10):
passvalue = joinArray(highest_index[i]+1,dat)
for i in range(0,38,2):
H = Data2.iloc[:, i:i+2]
H = H.dropna()
scaler = StandardScaler()
Sdatad1 = scaler.fit_transform(H)
h1 = sequenced(Sdatad1)
However, on running this code, I get this error:
AxisError: axis 1 is out of bounds for array of dimension 1
I have tried np.append(), np.vstack() also but all end up in errors. Is there a way this problem can be solved?
np.concatenaterequires careful attention to argument shapes. What the shape ofseq1, orseq?axis=1requires at least 2 dimensions. You can append elements to a list without much thought as to the contents, since it just adds a reference in-place.concatenate(and derivatives) makes a whole new array, and must align shapes just right. It's making a multidimensional array, not just taking on a reference.