这是我上一个问题的后续问题: Python3 Numpy np.where Error。
我有2个这样的列表:
x = [None,[1, 15, 175, 20],
[150, 175, 18, 20],
[150, 175, 18],
[192, 150, 177],...]
y = [None,[12, 43, 55, 231],
[243, 334, 44, 12],
[656, 145, 138],
[12, 150, 177],
[150, 177, 188],...]
我想删除小于30的x
值和与删除的y
值相对应的x
值。 (例如,(x,y) = (1,12)
和x[1]
中的y[1]
)
为此,我得到了更正的x
列表:
In : [[v2 for v2 in v1 if v2>=30] for v1 in x[1:]]
Out: [[175], [150, 175], [150, 175], [192, 150, 177]]
我还得到了其余x
个值的坐标:
In : [(i,j) for i,v1 in enumerate(x[1:]) for j,v2 in enumerate(v1) if v2<30]
Out: [(0, 0), (0, 1), (0, 3), (1, 2), (1, 3), (2, 2)]
现在,我想使用这些坐标从y
中删除项目。
我该如何实现?
答案 0 :(得分:1)
new_y = []
for i in range(len(y)):
new_y.append([y[i][j] for j in range(len(y[i])) if (i,j) not in BadList])
BadList
是
[(i,j) for i,v1 in enumerate(x[1:]) for j,v2 in enumerate(v1) if v2<30]
答案 1 :(得分:1)
您可以使用override fun onStart() {
super.onStart()
val cl: ConstraintLayout = findViewById(R.id.constraint_Layout)
cl.setBackgroundColor(color_Background)
}
和
<OutputClaim ClaimTypeReferenceId="givenName" />
<OutputClaim ClaimTypeReferenceId="objectId" PartnerClaimType="sub" />
<OutputClaim ClaimTypeReferenceId="surname" />
<OutputClaim ClaimTypeReferenceId="email"/>
<OutputClaim ClaimTypeReferenceId="signInNames.emailAddress"/>
<OutputClaim ClaimTypeReferenceId="otherMails"/>
这等效于
<ClaimType Id="email">
<DisplayName>Email Address</DisplayName>
<DataType>string</DataType>
<DefaultPartnerClaimTypes>
<Protocol Name="OAuth2" PartnerClaimType="email" />
<Protocol Name="OpenIdConnect" PartnerClaimType="email" />
<Protocol Name="SAML2" PartnerClaimType="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/email" />
</DefaultPartnerClaimTypes>
<TechnicalProfile Id="AAD-UserReadUsingObjectId">
...
<OutputClaims>
<OutputClaim ClaimTypeReferenceId="displayName" />
<OutputClaim ClaimTypeReferenceId="otherMails" />
<OutputClaim ClaimTypeReferenceId="email" PartnerClaimType="signInNames.emailAddress" />
<OutputClaim ClaimTypeReferenceId="givenName" />
<OutputClaim ClaimTypeReferenceId="userPrincipalName" />
<OutputClaim ClaimTypeReferenceId="surname" />
<UserJourney Id="SignInSaml">
<OrchestrationSteps>
<OrchestrationStep Order="1" Type="ClaimsExchange">
<ClaimsExchanges>
<ClaimsExchange Id="LocalAccountSigninEmailExchange" TechnicalProfileReferenceId="SelfAsserted-LocalAccountSignin-Email" />
</ClaimsExchanges>
</OrchestrationStep>
<OrchestrationStep Order="2" Type="ClaimsExchange">
<Preconditions>
<Precondition Type="ClaimEquals" ExecuteActionsIf="true">
<Value>authenticationSource</Value>
<Value>socialIdpAuthentication</Value>
<Action>SkipThisOrchestrationStep</Action>
</Precondition>
</Preconditions>
<ClaimsExchanges>
<ClaimsExchange Id="AADUserReadWithObjectId" TechnicalProfileReferenceId="AAD-UserReadUsingObjectId" />
</ClaimsExchanges>
</OrchestrationStep>
<OrchestrationStep Order="3" Type="SendClaims" CpimIssuerTechnicalProfileReferenceId="Saml2AssertionIssuer" />
</OrchestrationSteps>
<ClientDefinition ReferenceId="DefaultWeb" />
</UserJourney>
<RelyingParty>
<DefaultUserJourney ReferenceId="SignInSaml" />
<UserJourneyBehaviors>
<JourneyInsights TelemetryEngine="ApplicationInsights" InstrumentationKey="key" DeveloperMode="true" ClientEnabled="true" ServerEnabled="true" TelemetryVersion="1.0.0" />
</UserJourneyBehaviors>
<TechnicalProfile Id="PolicyProfile">
<DisplayName>PolicyProfile</DisplayName>
<Protocol Name="SAML2" />
<SubjectAuthenticationRequirements TimeToLive="40000" ResetExpiryWhenTokenIssued="false" />
<Metadata>
<Item Key="PartnerEntity"><![CDATA[<md:EntityDescriptor
xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" validUntil="2026-12-27T23:42:22.079Z" entityID="someentityid"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"><md:SPSSODescriptor WantAssertionsSigned="true" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol"><md:NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified</md:NameIDFormat><md:AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="https://sptest.iamshowcase.com/acs" index="0" isDefault="true"/></md:SPSSODescriptor></md:EntityDescriptor>]]></Item>
</Metadata>
<OutputClaims>
<OutputClaim ClaimTypeReferenceId="givenName" />
<OutputClaim ClaimTypeReferenceId="objectId" PartnerClaimType="sub" />
<OutputClaim ClaimTypeReferenceId="surname" />
<OutputClaim ClaimTypeReferenceId="email" />
</OutputClaims>
<SubjectNamingInfo ClaimType="sub" />
</TechnicalProfile>
</RelyingParty>
哪里
zip
和
In [395]: [(a, b) for z in list(zip(x, y))[1:] for a, b in list(zip(*z)) if a >= 30]
Out[395]:
[(175, 55),
(150, 243),
(175, 334),
(150, 656),
(175, 145),
(192, 12),
(150, 150),
(177, 177)]
答案 2 :(得分:1)
要获得更正的y
值,我建议完全绕过坐标作为第一种方法。原因是您一路上可能会得到空列表,这会使您的输出形状变差,而不必特别跟踪它们。另外,删除元素通常比不首先包含元素要难得多。
以更正y
的相同方式制作x
的更正版本会容易得多:
y_corr = [[n for m, n in zip(row_x, row_y) if m >= 30] for row_x, row_y in zip(x, y)]
在这里,我们只是使用zip
来浏览两组列表,就像处理一个列表一样。
如果您绝对坚持使用坐标,则建议您完全复制y
并从更正后的副本中删除元素。您必须在每行中向后移动,以避免移动坐标的含义(例如,使用reversed
)。您可以使用itertools.groupby
对每一行进行实际的迭代:
y_corr = [row.copy() for row in y]
for r, group in groupby(reversed(coord), itemgetter(0)):
for c in map(itemgetter(1), group):
del y_corr[r][c]
您可以单独反转每个组,而不是反转coord
,例如与map(itemgetter(1), reversed(group))
。
更好的方法可能是计算保留值的坐标,而不是舍弃值。我建议您预先分配输出列表,以帮助跟踪空列表并保留形状:
from itertools import groupby
from operator import itemgetter
coord = [(r, c) for r, row in enumerate(x) for c, n in enumerate(row) if n >= 30]
y_corr = [[]] * len(x)
for r, group in groupby(coord, itemgetter(0)):
y_corr[r] = [y[r][c] for c in map(itemgetter(1), group)]
如果您不关心保留空行,则可以跳过循环并改用单线:
y_corr = [[y[r][c] for c in map(itemgetter(1), group)] for r, group in groupby(coord, itemgetter(0))]