我使用以下NumPy数组创建了一个列表
a=np.arange(1,10,1)
b=np.arange(10,19,1)
c=np.arange(19,28,1)
#a= [1,2,3,4,5,6,7,8,9]
#b = [10,11,12,13, 14,15,16, 17,18]
#c =[19,20,21,22,23,24,25,26,27]
list_array = [a,b,c]
但是,当我尝试使用list_array.remove从列表中删除任何数组时,出现以下错误
list_array.remove(b)
>>ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
我的问题是如何从numpy数组列表中删除数组?
答案 0 :(得分:2)
Python没有“ where”关键字。您必须先声明您的数组,然后再声明数组的数组,然后您就可以毫无问题地删除它。
为您提供信息,Python中没有数组,只有列表中可以放置所需的任何类型。编写a = ["hello", 2, 6.48]
是完全有效的。
a= [1,2,3,
4,5,6,
7,8,9]
b = [10,11,12,
13, 14,15,
16, 17,18]
c =[19,20,21,
22,23,24,
25,26,27]
list_array = [a, b, c]
list_array.remove(b)
print(list_array) #Prints [a, c]
答案 1 :(得分:1)
您可以使用<table mat-table [dataSource]="clients">
<ng-container matColumnDef="client-name">
<th mat-header-cell *matHeaderCellDef>header</th>
<td mat-cell *matCellDef="let client">
<mat-checkbox (click)="onClientClick(client)"
[disabled]="client.disabled" [checked]="client.selected">
{{ client.name }}
</mat-checkbox>
</td>
</ng-container>
<tr mat-row *matRowDef="let row; columns: displayedColumnsClients"></tr>
测试两个numpy数组是否相等。
您将把它与自己的循环结合起来以实现与np.array_equiv
等效的功能,例如:
remove
如果愿意,您可以将import numpy as np
a = np.array([[1,2,3],[4,5,6],[7,8,9]])
b = a+9
c = b+9
list_array = [a,b,c]
for i in range(len(list_array) - 1, -1, -1):
if np.array_equiv(list_array[i], a):
list_array.pop(i)
print(list_array)
语句写为:
for
但重要的是它在索引向后中循环。