我想在 Google 查询语言中实现一系列带有舍入的查询,例如:
select round(age,-1), count(id) group by round(age,-1)
Run Code Online (Sandbox Code Playgroud)
或int/floor/等的任意组合。
select int(age/10)*10, count(id) group by int(age/10)*10
Run Code Online (Sandbox Code Playgroud)
有什么办法可以做到这一点吗?我怀疑不会,因为 GQL 中的标量函数列表非常有限,但确实想知道是否有解决方法。
http://code.google.com/apis/chart/interactive/docs/querylanguage.html#scalar_functions
我有一个使用PDL
. 最后一步是点积,因此它返回一个标量。然而,当我尝试打印这个标量时,它显然仍然是一个小数点,并在屏幕上打印如下:
[
[ 3 ]
]
Run Code Online (Sandbox Code Playgroud)
我想知道如何将它转换回常规 Perl 标量,以便它打印如下:
3
Run Code Online (Sandbox Code Playgroud)
更重要的是,如果我不转换并将该 piddle 在纯 Perl 上下文(不涉及 PDL)中进行进一步的算术操作,会产生什么后果。谢谢!
我正在尝试按照Nexus-Schema (nexusjs)网站上的文档向我的 GraphQL 应用程序添加标量类型。
\n我尝试src/types/Types.ts
使用文档和交互式示例中提供的示例将许多不同的实现添加到我的文件中。我的尝试包括:
没有第三方库:
\nconst DateScalar = scalarType({\n name: \'Date\',\n asNexusMethod: \'date\',\n description: \'Date custom scalar type\',\n parseValue(value) {\n return new Date(value)\n },\n serialize(value) {\n return value.getTime()\n },\n parseLiteral(ast) {\n if (ast.kind === Kind.INT) {\n return new Date(ast.value)\n }\n return null\n },\n})\n
Run Code Online (Sandbox Code Playgroud)\n使用graphql-iso-date
第 3 方库:
import { GraphQLDate } from \'graphql-iso-date\'\nexport const DateTime = GraphQLDate\n
Run Code Online (Sandbox Code Playgroud)\n使用第 3 方库(如Ghost 示例graphql-scalars
所示):
export const GQLDate …
Run Code Online (Sandbox Code Playgroud) 我看到一些代码在scalars(数字)上调用方法,类似于:
print 42->is_odd
Run Code Online (Sandbox Code Playgroud)
你有什么重载,以便你可以在你的代码中实现这种"功能"?
我刚刚开始学习perl,我对此练习感到困惑(来自Learning Perl第4章).
在greet()子例程的开头,我试图将参数$ _分配给我的$ name(我的$ name = $ _)变量,但它不起作用.这本书说要用"我的名字=班次"; 但我不明白为什么.shift用于从数组中删除一个值,据我所知,我的参数不是一个数组,它是一个标量内的字符串!
谁能解释一下我不理解的东西?
谢谢!这是整个代码.
use 5.012;
use warnings;
use utf8;
sub greet {
my $name = $_;
state $last_person ;
if (defined $last_person ) {
print "Hi $name! $last_person is also here!\n";
} else {
print "Hi $name! You are the first one here!\n";
}
$last_person = $name;
}
greet( 'Fred' );
greet( 'Barney' );
greet( 'Wilma' );
greet( 'Betty' );
Run Code Online (Sandbox Code Playgroud) 看起来好像标量本身就是一个项目的列表:
> "foo"[1]
Index out of range. Is: 1, should be in 0..0
in block <unit> at <unknown file> line 5
> "foo"[0]
foo
> "foo"[*-1]
foo
Run Code Online (Sandbox Code Playgroud)
我说的是一个列表,因为列表似乎没有索引的范围:
> (0, 1, 2)[3]
Nil
Run Code Online (Sandbox Code Playgroud)
这里发生了什么.我对[]
运营商的了解不多.
试图得到线性方程y = m*x + c
。我有以下几行代码,试图向数组添加标量。
m = 1.1; c = 0.11;
x = rand(1,2)
1×2 Array{Float64,2}:
0.920045 0.660015
y = m*x + c
ERROR: MethodError: no method matching +(::Array{Float64,2}, ::Float64)
Closest candidates are:
+(::Any, ::Any, ::Any, ::Any...) at operators.jl:502
+(::Bool, ::T<:AbstractFloat) where T<:AbstractFloat at bool.jl:112
+(::Float64, ::Float64) at float.jl:395
...
Stacktrace:
[1] top-level scope at none:0
Run Code Online (Sandbox Code Playgroud)
当前使用Julia 1.0。直接向数组添加标量不起作用。我以前认为在以前的版本中可以正常工作。
标量乘法工作
m*x
1×2 Array{Float64,2}:
1.01205 0.726016
Run Code Online (Sandbox Code Playgroud)
但是我必须定义另一个数组,然后如图所示执行加法。
c = [0.11 0.11]
y = m*x + c
1×2 Array{Float64,2}:
1.12205 0.836016 …
Run Code Online (Sandbox Code Playgroud) 我刚刚开始学习 Pytorch 并创建了我的第一个 CNN。该数据集包含 3360 张 RGB 图像,我将它们转换为[3360, 3, 224, 224]
张量。数据和标签在dataset(torch.utils.data.TensorDataset)
. 下面是训练代码。
def train_net():
dataset = ld.load()
data_iter = Data.DataLoader(dataset, batch_size=168, shuffle=True)
net = model.VGG_19()
summary(net, (3, 224, 224), device="cpu")
loss_func = nn.CrossEntropyLoss()
optimizer = optim.SGD(net.parameters(), lr=0.001, momentum=0.9, dampening=0.1)
scheduler = torch.optim.lr_scheduler.StepLR(optimizer, step_size=50, gamma=0.1)
for epoch in range(5):
print("epoch:", epoch + 1)
train_loss = 0
for i, data in enumerate(data_iter, 0):
x, y = data
print(x.dtype)
optimizer.zero_grad()
out = net(x)
loss = loss_func(out, y)
loss.backward()
optimizer.step() …
Run Code Online (Sandbox Code Playgroud) 考虑以下示例:
\n$null
foreach ($n in $null) {'This is a $null test'}\n(no output)\n\n$null | ForEach-Object {'This is a $null test'}\nThis is a $null test\n\n$null -in $null\nTrue\n\n$null -contains $null\nTrue\n
Run Code Online (Sandbox Code Playgroud)\n\xc2\xa0\n
[int]1
foreach ($n in [int]1) {'Test'}\nTest\n\n[int]1 | ForEach-Object {'Test'}\nTest\n\n[int]1 -in [int]1\nTrue\n\n[int]1 -contains [int]1\nTrue\n
Run Code Online (Sandbox Code Playgroud)\n
\n由于 $null 是一个不包含任何内容的标量值,因此在第二个 $null 示例中,$null 将沿着管道发送一个“nothing”的单个实例,这解释了输出。
$null
为什么即使$null -in $null
返回也不能作为集合进行迭代True
作为集合进行迭代?