小编Luc*_*ter的帖子

设置 torch.gather(...) 调用的结果

我有一个形状为 n x m 的 2D pytorch 张量。我想使用索引列表(可以使用 torch.gather 完成)对第二个维度进行索引,然后还将新值设置为索引的结果。

例子:

data = torch.tensor([[0,1,2], [3,4,5], [6,7,8]]) # shape (3,3)
indices = torch.tensor([1,2,1], dtype=torch.long).unsqueeze(-1) # shape (3,1)
# data tensor:
# tensor([[0, 1, 2],
#         [3, 4, 5],
#         [6, 7, 8]])
Run Code Online (Sandbox Code Playgroud)

我想选择每行指定的索引(但随后[1,5,7]也将这些值设置为另一个数字 - 例如 42

我可以通过执行以下操作来逐行选择所需的列:

data.gather(1, indices)
tensor([[1],
        [5],
        [7]])
data.gather(1, indices)[:] = 42 # **This does NOT work**, since the result of gather 
                                # does not use the same storage as the original tensor …
Run Code Online (Sandbox Code Playgroud)

python indexing pytorch tensor

6
推荐指数
1
解决办法
2256
查看次数

从app.xaml.cs WPF按顺序启动两个窗口

我想让用户在MainWindow出现之前登录。

第一个窗口显示出来,工作正常,并且在关闭所有其他WindowName.ShowDialog()调用后不起作用。

我的代码:在app.xaml中,我删除了StartUpURI并将其替换为

 Startup="Application_Startup"
Run Code Online (Sandbox Code Playgroud)

看起来像这样(app.xaml.cs):

private void Application_Startup(object sender, StartupEventArgs e)
        {
            Window1 window1 = new Window1();
            window1.ShowDialog();

            MainWindow window2 = new MainWindow();
            window2.ShowDialog();
        }
Run Code Online (Sandbox Code Playgroud)

我有两个完全不变的窗户(除了标题),第二个看起来一样:

    <Window x:Class="Delete_Me.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Delete_Me"
        mc:Ignorable="d"
        Title="First window" Height="300" Width="300">
    <Grid>

    </Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)

后面的代码也保持不变。

问题 如何从app.xaml.cs依次启动两个窗口?还是有什么更好的方法呢?

我的方法是 尝试换掉两个窗口,它们没有任何变化。

当然,我可以从MainWindow的contructor / OnLoaded中启动LoginForm,但这似乎并不是解决该问题的理想方法。

如果身份验证失败,我甚至不想启动MainWindow。

有什么建议么?谢谢。

c# wpf xaml app.xaml

2
推荐指数
1
解决办法
607
查看次数

标签 统计

app.xaml ×1

c# ×1

indexing ×1

python ×1

pytorch ×1

tensor ×1

wpf ×1

xaml ×1