小编BBi*_*ell的帖子

如何控制台.Writeline IEnumerable <(int a,int b,int c)>?

我正在完成一些计算机科学练习,我很尴尬地说我不知道​​如何在VS Studio中控制打印上述代码.我已经尝试了好几天了,我的部分问题是我实际上并不知道上面提到的结构的名称(比喻说).我完成了我的作业,阅读了手册,但现在没有什么可做的,只是举起手来问问题.在线似乎有许多使用的例子,IEnumerable<int>但没有输出我能找到的元组.发布任何示例代码将不胜感激.

public static class PythagoreanTriplet
{
    public static IEnumerable<(int a, int b, int c)> TripletsWithSum(int sum)
    {
        return Enumerable.Range(1, sum - 1)
                         .SelectMany(a => Enumerable.Range(a + 1, sum - a - 1)
                                                    .Select(b => (a: a, b:b, c: sum - a - b)))
                         .Where( x => x.a * x.a + x.b * x.b == x.c * x.c);

    }
}


public static class testclass
{
    public static void Main()
    {
        int input = 121;
        var data = PythagoreanTriplet.TripletsWithSum(input); …
Run Code Online (Sandbox Code Playgroud)

c#

5
推荐指数
1
解决办法
114
查看次数

将 Minibatch 标准差应用于 Keras GAN 层的正确方法

我正在尝试通过向图层的特征图添加标准差变量来提高 GAN 模型的稳定性。我正在遵循GANs-in-Action git中设置的示例。数学本身对我来说很有意义。我的模型的机制以及解决模式崩溃的原因对我来说很有意义。然而,该示例的一个缺点是它们从未实际显示该代码是如何执行的。

def minibatch_std_layer(layer, group_size=4):
    group_size = keras.backend.minimum(group_size, tf.shape(layer)[0])

    shape = list(keras.backend.int_shape(input))
    shape[0] = tf.shape(input)[0]

    minibatch = keras.backend.reshape(layer,(group_size, -1, shape[1], shape[2], shape[3]))
    minibatch -= tf.reduce_mean(minibatch, axis=0, keepdims=True)
    minibatch = tf.reduce_mean(keras.backend.square(minibatch), axis = 0)
    minibatch = keras.backend.square(minibatch + 1e8)
    minibatch = tf.reduce_mean(minibatch, axis=[1,2,4], keepdims=True)
    minibatch = keras.backend.tile(minibatch,[group_size, 1, shape[2], shape[3]])
    return keras.backend.concatenate([layer, minibatch], axis=1)

def build_discriminator():

    const = ClipConstraint(0.01)

    discriminator_input = Input(shape=(4000,3), batch_size=BATCH_SIZE, name='discriminator_input')
    
    x = discriminator_input

    x = Conv1D(64, 3, strides=1, padding="same", kernel_constraint=const)(x)
    x = BatchNormalization()(x)
    x …
Run Code Online (Sandbox Code Playgroud)

python keras tensorflow

5
推荐指数
1
解决办法
1425
查看次数

令人困惑的开关/案例结果

当然在发布此错误之前我搜索了它.下面的代码返回:错误CS0029:无法在两个位置隐式地将类型'bool'转换为'string'.我误解为什么下面的代码没有返回字符串?想一想Stack Overflow可能会给出什么建议我已经尽力明确地转换为字符串,但只是设法让自己感到困惑.

public static class Bob
{
    public static string Response(string statement)
    {
        string teststring = statement;

        bool IsAllUpper(string input)
        {
            for (int i = 0; i < input.Length; i++)
            {
                if (Char.IsLetter(input[i]) && !Char.IsUpper(input[i]))
                    return false;
            }
            return true;
        }

        switch(teststring)
        {
        case IsAllUpper(teststring) && teststring.EndsWith("?"):
            string final1 = "Calm down, I know what I'm doing!";
            return final1;   

        case teststring.EndsWith("?"):
            string final2 = "Sure";
            return final2;

        default:
            string final3 = "Whatever.";
            return final3;
        }
    } …
Run Code Online (Sandbox Code Playgroud)

c# switch-statement

-1
推荐指数
1
解决办法
58
查看次数

标签 统计

c# ×2

keras ×1

python ×1

switch-statement ×1

tensorflow ×1