我正在阅读一些深度学习代码。我对 numpy 数组中的高级索引有问题。我正在测试的代码:
import numpy
x = numpy.arange(2 * 8 * 3 * 64).reshape((2, 8, 3, 64))
x.shape
p1 = numpy.arange(2)[:, None]
sd = numpy.ones(2 * 64, dtype=int).reshape((2, 64))
p4 = numpy.arange(128 // 2)[None, :]
y = x[p1, :, sd, p4]
y.shape
Run Code Online (Sandbox Code Playgroud)
为什么形状y是(2, 64, 8)?
下面是上面代码的输出:
>>> x.shape
(2, 8, 3, 64)
>>> p1
array([[0], [1]])
>>> sd
array([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …Run Code Online (Sandbox Code Playgroud) 我尝试使用以下代码:
String hi = "hi";
String bye = "bye";
fprintf(fileout, "%d: %s, %s", 10, hi, bye); //fail
fprintf(fileout, "%d: %s, %s", 10, "hi", "bye");//ok
Run Code Online (Sandbox Code Playgroud)
但是,这不能写到文本文件.怎么了?
我写ac#program倒计时5秒.我所做的是:
new Task(() =>
{
try
{
this.Invoke((Action)delegate()
{
label1.Text = "5"; // 4, 3, 2..etc
});
}
Thread.Sleep(1000);
}
catch
{
// form could be disposed
break;
}
}
}).Start();
Run Code Online (Sandbox Code Playgroud)
这可以在我的电脑上运行,但是,当我将程序复制到平板电脑时,Thread.Sleep(1000)给出的时间超过1秒.换句话说,从5,4,3,2,1更新标签需要5秒以上(实际上超过10秒).或者,更新label1.Text ="5"等需要很长时间?这对我来说没有意义.我想知道出了什么问题?