[(x if c else y)for x, y, c in zip(xarr, yarr, cond)]
时间: 2024-06-06 12:07:17 浏览: 53
This is a list comprehension that creates a new list by iterating over three lists in parallel: xarr, yarr, and cond. For each element in these lists, it checks the corresponding value in the cond list. If the value is True, it selects the value from xarr, otherwise it selects the value from yarr. The resulting list contains the selected values from xarr and yarr based on the values in cond.
As an example, if xarr = [1, 2, 3], yarr = [4, 5, 6], and cond = [True, False, True], the resulting list would be [1, 5, 3]. This is because the first and third values in cond are True, so the corresponding values in xarr are selected, while the second value in cond is False, so the corresponding value in yarr is selected.
阅读全文