深度学习与PyTorch入门实战 - 13. Tensor统计## PyTorch ## 统计属性 主讲人:龙良曲 ## statistics - norm mean sum • prod max, min, argmin, argmax kthvalue, topk v.s. normalize ,e.g. batch norm ■ matrix norm v.s. vector norm ## V ector vs matrix Matrix 8 In [145]: a.sum() 9 Out[145]: tensor(28.) 11 In [147]: a.argmax(), a.argmin() 12 Out[147]: (tensor(7), tensor(0)) 13 ## argmin, argmax ## ☀️ ☀️ ☁️ 1 In [149]: a=a.view(1,2,4) 2 tensor([[0., 1. 5., 6., 7.]]]) 5 In [151]: a.argmax() 6 Out[151]: tensor(7) 8 In [152]: a.argmin() 9 Out[152]: tensor(0) 11 In [153]: a=torch.rand(2,3,4) 12 13 In [154]: a.argmax() 14 Out[154]: tensor(21) ##0 码力 | 11 页 | 1.28 MB | 2 年前3
深度学习与PyTorch入门实战 - 14. Tensor高阶# if dim == 1 out[i][j][k] = input[i][j][index[i][j][k]] # if dim == 2 ## retrieve global label argmax (pred) to get relative labeling - On some condition, our label is distinct from relative labeling0 码力 | 8 页 | 501.85 KB | 2 年前3
Solving Nim by the Use of Machine LearningcurReward = self.Q[curState][curAction] nextState = curAction nextAction = np.argmax(self.Q[nextState]) self.Q[curState][curAction] -= mu * (curReward + gamma * self.Q[n return tmpList[random.randrange(0, len(tmpList))] else: return np.argmax(self.Q[state]) Listing 8: The code for the Q-learning algorithm. Note that linenumbers are from tmpList.append(i) return tmpList[random.randrange(0, len(tmpList))] else: return np.argmax(self.Q[state]) Listing 9: The code for the Sarsa algorithm. Note that linenumbers are from the untrimmed0 码力 | 109 页 | 6.58 MB | 1 年前3
PyTorch OpenVINO 开发实战系列教程第一篇表示输出数组维度大小。 ## 其它属性操作 通道交换与寻找最大值是 Pytorch 中处理张量数据常用操作之一,这两个相关函数名称分别是 torch.transpose 与 torch.argmax,支持张量直接操作。代码演示如下: argmax,支持张量直接操作。代码演示如下: x = torch.randn(5, 5, 3) print(x.size()) x = x.transpose(2, 0) print(x print(x.size()) x = torch.tensor([2., 3., 4., 12., 3., 5., 8., 1.]) print(torch.argmax(x)) x = x.view(-1, 4) print(x.argmax(1)) 运行结果如下: torch.Size([5, 5, 3]) torch.Size([3, 5, 5]) tensor(3) tensor([3, 2]) 运行结果的第一行对应是声明的张量 x 的维度信息、第二行是调用 transpose 方法完成通道交换之后 x 输出的维度信息;第三行是针对 x 调用 argmax 得到最大值对应索引(12 对应索引值为 3)、第四行是进行维度变换之后针对二维数据(2×4)的第二个维度调用 argmax 得到的输出,分别是 12 与 8 对应的索引值 [3,2]。 ## CPU 与 GPU 运算支持 Pytorch 支持 CPU0 码力 | 13 页 | 5.99 MB | 2 年前3
全连接神经网络实战. pytorch 版pred = model(X) test_loss += loss_function(pred, y).item() correct += (pred.argmax(1) == y).type(torch.float).sum().item() test_loss /= num_batches correct /= size pri 个数据,with torch.no_grad() 的意义是不再构建计算图。因为 pytorch 在运算时会首先构建计算图,用于后面的反向传播算法等操作,我们测试正确率时不需要构建计算图。pred.argmax(1) 表示向量中最大的一个数的索引,即为我们预测的当前数据类别。然后,.sum 函数得到一个 batch 里的所有预测正确的次数。 现在我们的网络已经可以训练了,我们可以看到,最终训练的模型在测试集上的准确率为百分之70左右。 torch.tensor([y]) test_loss += loss_function(pred, y).item() correct += (pred.argmax(1) == y).type(torch.float).sum().item() test_loss /= size correct /= size print(f"Test_Error:0 码力 | 29 页 | 1.40 MB | 2 年前3
深度学习与PyTorch入门实战 - 29. MNIST测试/p2_2.jpg) argmax ## ☐ ☐ ☐ In [60]: logits=torch.rand(4, 10) In [62]: pred=F.softmax(logits, dim=1) In [63]: pred.shape Out[63]: torch.Size([4, 10]) In [64]: pred_label=pred.argmax(dim=1) In [65]: [65]: pred_label Out[65]: tensor([9, 5, 9, 4]) In [66]: logits.argmax(dim=1) Out[66]: tensor([9, 5, 9, 4]) In [67]: label=torch.tensor([9,3,2,4]) In [68]: correct=torch.eq(pred_label, label) Out[69]: target.cuda() logits = net(data) test_loss += criteon(logits, target).item() pred = logits.argmax(dim=1) correct += pred.eq(target).float().sum().item() test_loss /= len(test_loader.dataset) print("\nTest0 码力 | 7 页 | 713.39 KB | 2 年前3
pandas: powerful Python data analysis toolkit - 0.17.0other NDFrame objects. See Internal Refactoring for more information. • Series.argmin and Series.argmax are now aliased to Series.idxmin and Series.idxmax. These return the i min or max element respectively powerful Python data analysis toolkit, Release 0.17.0 Note: idxmin and idxmax are called argmin and argmax in NumPy. 10.5.3 Value counts (histogramming) / Mode The value_counts() Series method and top-level Concatenate two or more Series. apply(func[, convert_dtype, args]) Invoke function on values of Series. argmax([axis, out, skipna]) Index of first occurrence of maximum of values. argmin([axis, out, skipna])0 码力 | 1787 页 | 10.76 MB | 2 年前3
pandas: powerful Python data analysis toolkit - 0.15other NDFrame objects. See Internal Refactoring for more information. • Series.argmin and Series.argmax are now aliased to Series.idxmin and Series.idxmax. These return the i min or max element respectively 1 b 3 a NaN In [97]: df3[’A’].idxmin() Out[97]: ’d’ Note: idxmin and idxmax are called argmin and argmax in NumPy. 9.5.3 Value counts (histogramming) / Mode The value_counts Series method and top-level apply(func[, convert_dtype, args]) Invoke function on values of Series. Can be ufunc (a NumPy function argmax([axis, out, skipna]) Index of first occurrence of maximum of values. argmin([axis, out, skipna])0 码力 | 1579 页 | 9.15 MB | 2 年前3
pandas: powerful Python data analysis toolkit - 0.21.1select and DataFrame.select . . . . . . . . . . . . . . . . . . . . . . . . . . 26 1.2.3.2 Series.argmax and Series.argmin . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 1.2.4 Removal of prior append . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1735 34.6.1.30 pandas.Index.argmax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1735 34.6.1.31 pandas.Index.argmin append . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1776 34.10.1.34pandas.MultiIndex.argmax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1776 34.10.1.35pandas.MultiIndex.argmin0 码力 | 2207 页 | 8.59 MB | 2 年前3
pandas: powerful Python data analysis toolkit - 0.13.1other NDFrame objects. See Internal Refactoring for more information. • Series.argmin and Series.argmax are now aliased to Series.idxmin and Series.idxmax. These return the i 1.2. v0.13.0 (January 3, 2014) 1 columns] In [85]: df3[’A’].idxmin() Out[85]: ’d’ Note: idxmin and idxmax are called argmin and argmax in NumPy. 9.5.3 Value counts (histogramming) / Mode The value_counts Series method and top-level apply(func[, convert_dtype, args]) Invoke function on values of Series. Can be ufunc (a NumPy function argmax([axis, out, skipna]) Index of first occurrence of maximum of values. argmin([axis, out, skipna])0 码力 | 1219 页 | 4.81 MB | 2 年前3
共 152 条
- 1
- 2
- 3
- 4
- 5
- 6
- 16













