小编Wol*_*olf的帖子

向数组添加附加维度

注意:此问题/答案是从Julia Slack频道复制的。

如果我有一个任意的Julia Array,该如何添加另一个维度。

julia> a = [1, 2, 3, 4]
4-element Array{Int64,1}:
 1
 2
 3
 4
Run Code Online (Sandbox Code Playgroud)

所需的输出将是例如:

julia> a[some_magic, :]
1×4 Array{Int64,2}:
 1  2  3  4
Run Code Online (Sandbox Code Playgroud)

要么:

julia> a[:, some_magic]
4×1 Array{Int64,2}:
 1
 2
 3
 4

Run Code Online (Sandbox Code Playgroud)

julia

6
推荐指数
1
解决办法
54
查看次数

遍历字符串失败,出现StringIndexError

注意:这个问题是由这个话语线索引起的

考虑以下示例字符串:

str = "This is some text that initially consists of normal ASCII characters—but oh wait, the em-dash is only part of the extended ASCII character set!"
Run Code Online (Sandbox Code Playgroud)

尝试使用其长度遍历此字符串:

for i in 1:length(str)
  println(i, str[i])
end
Run Code Online (Sandbox Code Playgroud)

失败StringIndexError,返回循环中途返回以下消息:

ERROR: StringIndexError("This is some text that initially consists of normal ASCII characters—but oh wait, the em-dash is only part of the extended ASCII character set!", 70)
Stacktrace:
 [1] string_index_err(::String, ::Int64) at ./strings/string.jl:12
 [2] getindex_continued(::String, ::Int64, ::UInt32) at ./strings/string.jl:217 …
Run Code Online (Sandbox Code Playgroud)

string julia

4
推荐指数
1
解决办法
53
查看次数

标签 统计

julia ×2

string ×1