random.sample(sequence, k),从指定序列中随机获取指定长度的片断。sample函数不会修改原有序列
numpy.nonzero() Return the indices of the elements that are non-zero.
>>> a = np.array([[1,2,3],[4,5,6],[7,8,9]]) >>> a > 3 array([[False, False, False], [ True, True, True], [ True, True, True]], dtype=bool) >>> np.nonzero(a > 3) (array([1, 1, 1, 2, 2, 2]), array([0, 1, 2, 0, 1, 2]))
时间: 2024-10-12 13:29:53