I have a collection of (6 by 6) matrices, In my code, I may get 5 to 6 matrices (of order (6 by 6).)
I wanted to delete certain rows and columns in each of these 5 to 6 matrices I have.
so I ran a for-loop
suppose for now, in that collection I have only "one" matrix (a_matrix of order 6 by 6).
Each matrix that comes into this for-loop should get reduced to 2 by 2 matrices shown below. (desired output)
this is my failed attempt, here a_matrix will not work as there is only a single 6 by 6 matrix in my collection.
it is showing an error as
ValueError: could not broadcast input array from shape (5) into shape (6)
import numpy as np
a_matrix = np.array ( [ [ 1, 2, 3, 4, 5, 6 ],
[ 7, 8, 9, 10, 11, 12 ],
[ 13, 14, 15, 16, 17, 18 ],
[ 19, 20, 21, 22, 23, 24 ],
[ 25, 26, 27, 28, 29, 30 ],
[ 31, 32, 33, 34, 35, 36 ]] )
total_no_of_matrices = 1
for i in range(total_no_of_matrices):
a_matrix[i] = np.delete(a_matrix[i], 0, 0)
a_matrix[i] = np.delete(a_matrix[i], 0, 0)
a_matrix[i] = np.delete(a_matrix[i], 1, 0)
a_matrix[i] = np.delete(a_matrix[i], 1, 0)
print(a_matrix)
desired output- (after deletion of certain rows and columns)
a_matrix = [[15, 18],
[33, 36]]