我想用julia中的整数填充数组。以下工作:
a = Array{Int64}[]
push!(a, [1,2,3])
但这并不是:
a = Array{Array{Int64}}[]
push!(a, [1, 2, 3])
错误是:MethodError: Cannot `convert` an object of type Int64 to an object of type Array{Int64,N} where N
谁能解释一下原因吗?看起来,Array{Array{Int64}}应该是数组的类型,其元素是包含Int64值的数组,而Array{Int64}是一个整数数组。然而,a =
我正在尝试移植一些代码,但现在遇到了一个棘手的问题。原始代码在C++中。我需要移植一个有两个32位整数(在一个数组中)和一个双精度数的联合。
到目前为止,我有:
I1 = UInt32(56) # arbitrary integer values for example
I2 = UInt32(1045195987)
# do transforms on I1 and I2 as per the code I'm porting
A = bits(I1)
B = bits(I2)
return parse(Float64, string(A,B))
这是做这件事的方法吗?字符串操作的开
两者有什么区别?
function foo(a::Adjoint{Float64, Matrix{T}} where T)
return 0
end
和
function foo(a::Adjoint{Float64, Matrix{T} where T})
return 1
end
(请注意花括号的位置。)
julia> methods(foo)
# 2 methods for generic function "foo":
[1] foo(a::Adjoint{Float64,Array{T,2}} where T) in Main at REPL[2
我在“朱莉娅词典”中遇到了奇怪的行为。在“朱莉娅”中,字典可以这样定义:
dictionary = Dict(1 => 77, 2 => 66, 3 => 1)
而且您可以使用keys访问密钥。
> keys(dictionary)
# [output]
KeySet for a Dict{Int64, Int64} with 3 entries. Keys:
2
3
1
# now i want to make sure Julia consider above order. so i use collect and then i will call first
我现在开始使用Julia,我需要插值一个布朗运动。我运行了以下代码,但出现了以下错误。 N = 3
B = zeros(N)
B[N] = randn(1) 这会抛出: MethodError: Cannot `convert` an object of type Vector{Float64} to an object of type Float64
我对数组的不同类型感到困惑。考虑这两个例子
a = Array{Float64}[]
push!(a,[1, 2])
push!(a,[3, 4])
push!(a,[1 2; 3 4])
b = Array[[1.0, 2.0], [3.0,4.0], [1.0 2.0; 3.0 4.0]]
我不知道a和b有什么不同。假设我打算对a或b中的每个元素运行一个for循环,并将每个元素乘以2。
for i in 1:3 a[i] = a[i]*2 end
for i in 1:3 b[i] = b[i]*2 end
我分别对两行的运行时间进行计时,但它们的运行速度是相同的。a和b是一样的吗?如
朱莉娅是否有命令来找到向量最小值的索引?例如,R有一个which.min命令(当然还有一个which.max )。
显然,我可以自己写以下内容,但最好不用写。
function whichmin( x::Vector )
i = 1
min_x=minimum(x)
while( x[i] > min_x )
i+=1
end
return i
end
如果之前有人问过这件事,我很抱歉,但我找不到。谢谢!
我试图使用单元格作为Julia函数的输入,如下所示
U = cell(2) U[1] = zeros(3,3) U[2] = zeros(3,3)
function f_test{S<:AbstractFloat}(U::Array{S}) a = zero(S) return a end
我知道:f_test(U)和我
LoadError: MethodError:f_testhas no method matching f_test(::Array{Any,1}) while loading In[391], in expression starting on line 10
我想通过将长度为h的较小列向量G重复n次来创建列向量X。
G = [1;2;3;4] #column vector of length h
X = [1;2;3;4;1;2;3;4;1;2;3;4] #ie X = [G;G;G;G] column vector of
length h*n
当我尝试在这种情况下使用fill时,我得到的不是一个长度为h*n的列向量,而是一个长度为n的列向量,其中每一行都是另一个长度为h的向量。例如,我得到了以下内容:
X = [[1,2,3,4];[1,2,3,4];[1,2,3,4];[1,2,3,4]]
这对我来说没有任何意义,因为我知道;符号用于显示行中的
我想比较朱莉娅的字符串列表中的每一对字符串。一种方法就是
equal_strs = [(x == y) for x in str_list, y in str_list]
但是,如果我按以下方式使用广播:
equal_strs = broadcast(==, str_list, str_list)
它返回一个向量而不是一个二维数组。有没有办法用broadcast输出二维数组?