我有一个形状为(25,10)的矩阵,也可以是25以外的任何其他数字。我想删除多余的行并得到形状为(20,10)的矩阵
答案 0 :(得分:1)
# Let's say your matrix is stored in a variable called "my_matrix"
# then you can do something like this:
my_matrix = my_matrix[:20] # equals to: my_matrix[0:20]
# or:
my_matrix = my_matrix[2:22]
# or if you are using numpy:
indices_to_keep = np.asarray([...indices of elements you want to keep...])
my_matrix = my_matrix[indices_to_keep]