有没有办法覆盖[]数组中的范围补充?
julia> a=[1:8...]
8-element Array{Int64,1}:
1
2
3
4
5
6
7
8
julia> a[-1] == a[2:8]
julia> a[-(1:3)] == a[4:8]
julia> a[-end] == a[1:7]
Run Code Online (Sandbox Code Playgroud) 有没有办法从网络URL或runpipe外部命令读取表?似乎DataFrame.readtable仅支持从文件读取.
例如在R中我们可以做到:
df = read.table(url("http://example.com/data.txt"))
x = read.table(pipe("zcat data.txt | sed /^#/d | cut -f '11-13'"), colClasses=c("integer","integer","integer"), fill=TRUE, row.names=NULL)
Run Code Online (Sandbox Code Playgroud) include_oncejulia 中是否有一种方法include只能对文件执行一次,就像C++ 中的方法#pragma once一样#ifndef?
我想查看 REPL 中方法的定义。我点击此链接(https://github.com/JuliaLang/julia/issues/2625),但它不起作用:
julia> f(x) = x^2
f (generic function with 1 method)
julia> expand(f)
f (generic function with 1 method)
julia> methods(f)
# 1 method for generic function "f":
f(x) at REPL[155]:1
julia> implementation(f,1)
ERROR: UndefVarError: implementation not defined
in eval_user_input(::Any, ::Base.REPL.REPLBackend) at ./REPL.jl:64
in macro expansion at ./REPL.jl:95 [inlined]
in (::Base.REPL.##3#4{Base.REPL.REPLBackend})() at ./event.jl:68
Run Code Online (Sandbox Code Playgroud)
好像这个方法implementation不存在。
在REPL中调试或运行julia代码时,我通常会看到错误消息... at ./REPL[161]:12 [inlined]....这个数字161意味着161-thREPL中的评估,我猜.所以我的问题是我们可以在朱莉娅的提示中显示这个数字,julia [161]>而不是julia>?
我想创建一个引号,它将符号:abc保存在变量中x并将其推入数组中a.但是我只能获得变量abc.语法:$x似乎不正确(不是我想要的).这样做的语法是什么?:
julia> x = :abc
julia> expr = quote
a = []
push!(a, $x)
push!(a, :($x))
push!(a, :$x)
a
end
quote
a = []
push!(a, abc)
push!(a, $(Expr(:quote, :($(Expr(:$, :x))))))
push!(a, :$ * x)
a
end
Run Code Online (Sandbox Code Playgroud)
所需的输出是:
quote
a = []
push!(a, :abc)
a
end
Run Code Online (Sandbox Code Playgroud) 我想浅复制一个结构以仅复制值但保留其中的集合引用。但似乎没有内置方法:
julia> mutable struct S
x
y
end
julia> a = S(1, rand(2))
S(1, [0.792705, 0.582458])
julia> b = deepcopy(a)
S(1, [0.792705, 0.582458])
julia> b.y === a.y
false
julia>
julia> b = copy(a)
ERROR: MethodError: no method matching copy(::S)
Closest candidates are:
copy(::Expr) at expr.jl:36
copy(::BitSet) at bitset.jl:46
copy(::Markdown.MD) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v0.7/Markdown/src/parse/parse.jl:30
...
Stacktrace:
[1] top-level scope at none:0
julia> b.y === a.y # expect true
Run Code Online (Sandbox Code Playgroud) 我想将一组函数应用于值并获取一组值作为输出.我在help?> groupby(DataFrames包)中看到我们可以做到:
> df |> groupby(:a) |> [sum, length]
> df |> groupby([:a, :b]) |> [sum, length]
Run Code Online (Sandbox Code Playgroud)
但我们能做到吗
> [sum, length](groupby([:a, :b]))
MethodError: objects of type Array{Function,1} are not callable
square brackets [] for indexing an Array.
eval_user_input(::Any, ::Base.REPL.REPLBackend) at ./REPL.jl:64
in macro expansion at ./REPL.jl:95 [inlined]
in (::Base.REPL.##3#4{Base.REPL.REPLBackend})() at ./event.jl:68
Run Code Online (Sandbox Code Playgroud)
甚至
> [sum, length](1:5)
Run Code Online (Sandbox Code Playgroud)
我期待输出:
[15, 5]
Run Code Online (Sandbox Code Playgroud) 有没有一种方法可以将字符串转换为 Expr?我尝试了以下方法,但它不起作用:
julia> convert(Expr, "a=2")
ERROR: MethodError: Cannot `convert` an object of type String to an object of type Expr
This may have arisen from a call to the constructor Expr(...),
since type constructors fall back to convert methods.
julia> Expr("a=2")
ERROR: TypeError: Expr: expected Symbol, got String
in Expr(::Any) at ./boot.jl:279
Run Code Online (Sandbox Code Playgroud) 我如何检查嵌套数组的元素类型,因为我不知道嵌套的级别?:
julia> a = [[[[1]]]]
1-element Array{Array{Array{Array{Int64,1},1},1},1}:
Array{Array{Int64,1},1}[Array{Int64,1}[[1]]]
julia> etype(a)
Int64?
Run Code Online (Sandbox Code Playgroud)