python - Appending matrices -


Suppose my matrix is ​​that I delete a whole line and after doing this, I delete the deleted row in the lower matrix Want to add how can I do this?

np a = np Import as Array ([1,2,3], [4,5,6], [7,8,9]] A1 = np.delete (A, 1.0) A2 = A [1] ,:] Np.append (A1, A2,0)

but this error is showing.

Any suggestions?

when you np.delete array without the deleted row Gives the line not deleted, then your A1 is actually two rows instead of one, and this is the reason that it is failing.

To achieve what you want, it should:

  A1 = A [1] A = N.P. deleit (A, 1, 0) Result = NP.Append (A, A1 [NP.Newexis ,:], 0)  

and this will result in

  array ([[1, 2, 3], [7, 8, 9], [4, 5, 6]])  

Did you want it?

Note that to use np.newaxis is necessary to attach a single row line A1 to the same size as the array (because np.append Requires arrays to keep the same number of dimensions)


Comments