当我正在进行切片时,发生了意想不到的事情,这似乎是第一个被查看但第二个是复制.
第一片行,然后是片段.这似乎是一种观点.
>>> a = np.arange(12).reshape(3, 4)
>>> a[0:3:2, :][:, [0, 2]] = 100
>>> a
array([[100, 1, 100, 3],
[ 4, 5, 6, 7],
[100, 9, 100, 11]])
Run Code Online (Sandbox Code Playgroud)
但是,如果我第一次切片,然后切片行,它似乎是一个副本:
>>> a[:, [0, 2]][0:3:2, :] = 0
>>> a
array([[100, 1, 100, 3],
[ 4, 5, 6, 7],
[100, 9, 100, 11]])
Run Code Online (Sandbox Code Playgroud)
我很困惑,因为这两种方法最终会导致看似位置改变,但为什么第二种方法实际上不会改变数字?
在C#中,如果我们想向Console输出错误,我们可以简单地写:
Console.Error.Write("Error!");
Run Code Online (Sandbox Code Playgroud)
但是当我尝试向Console写警告时,我发现没有:
Console.Warning.Write("Warning!");
Run Code Online (Sandbox Code Playgroud)
相反,我需要写:
WarningException myEx=new WarningException("This is a warning");
Console.Write(myEx.ToString());
Run Code Online (Sandbox Code Playgroud)
为什么它的设计符合这种格式?
我有一个enum Color,它可能派生自longor byteor int,我想知道它真正派生自什么类型,longor byteor int?在这个过程中,我遇到了2个问题。
首先, 的Color定义如下:
enum Color : long
{
red = 1,
black = 2,
blue = 3
}
Run Code Online (Sandbox Code Playgroud)
我编写下面的代码来执行此类操作:
Console.WriteLine(typeof(Color)); // ConsoleApp7.Color
Console.WriteLine(typeof(Color).BaseType); // System.Enum
Run Code Online (Sandbox Code Playgroud)
这时,我遇到了我的第一个问题:很好奇的是typeof(Color).BaseType,System.Enum因为Color是一种enum类型。
所以我想知道您是否定义了enum类似的类型enum Enum1 { ... },它实际上意味着:class Enum1 : enum { ... }?
基于问题1,如果我想得到它真正的基类型,我需要写:
Console.WriteLine(typeof(Color).BaseType.BaseType);
Run Code Online (Sandbox Code Playgroud)
它的输出是System.ValueType,我们知道int,byte …