numpy数组如何获取最小行索引

时间:2020-05-31 01:28:22

标签: python numpy

我有一个像这样的numpy数组

# [[0.64809866 1.4297429  1.76778859]
#  [0.98994126 0.60583935 1.07312068]
#  [0.47607127 0.58659789 1.52184562]
#  [0.6905903  0.33424117 1.50113122]
#  [0.66848235 1.5608329  2.02750987]

我想找到每一行的最小值,但要通过索引知道。像这样

# [[0]
#  [1]
#  [0]
#  [1]
#  [0]]

我使用np.min(dist, axis=1).reshape(-1, 1)来生成具有最小结果的矩阵,但不知道如何从此处开始。

1 个答案:

答案 0 :(得分:2)

尝试使用struct Queue<T> { var list: LinkedList<T> init(_ initialElements: T...) { self.list = LinkedList(initialElements) } mutating func push(_ newElement: T) { let newHead = LinkedList.Node(value: newElement, next: self.list.head) self.list.head = newHead } mutating func pop() -> T? { guard let head = self.list.head else { return nil } self.list.head = head.next return head.value } } var q = Queue(3, 2, 1) print(q) // => Queue<Int>(list: LinkedList[3, 2, 1]) q.push(4); print(q) // => Queue<Int>(list: LinkedList[4, 3, 2, 1]) q.push(5); print(q) // => Queue<Int>(list: LinkedList[5, 4, 3, 2, 1]) print(q.pop(), q) // => Optional(5) Queue<Int>(list: LinkedList[4, 3, 2, 1]) print(q.pop(), q) // => Optional(4) Queue<Int>(list: LinkedList[3, 2, 1]) print(q.pop(), q) // => Optional(3) Queue<Int>(list: LinkedList[2, 1]) print(q.pop(), q) // => Optional(2) Queue<Int>(list: LinkedList[1]) print(q.pop(), q) // => Optional(1) Queue<Int>(list: LinkedList[empty]) print(q.pop(), q) // => nil Queue<Int>(list: LinkedList[empty])

argmin
相关问题