[英]how to convert an array{Float64,1} to a Float64? in julia
I just want to know how to convert an array{Float64,1} to a Float64? 我只想知道如何将数组{Float64,1}转换为Float64? in julia 在朱莉娅
utility= rand(1)*row*c*(1-x)
it gives me error "array of size (1,) passed as objective; only scalar objectives are allowed" 它给我错误“作为目标传递的大小为(1,)的数组;仅允许标量目标”
Just use rand()
instead of rand(1)
. 只需使用rand()
而不是rand(1)
。 The former returns a random Float64
value, whereas the latter returns a 1-dimensional array with one element in it. 前者返回随机的Float64
值,而后者返回其中包含一个元素的一维数组。 Better to keep everything as scalars in the first place if it's possible to do so. 如果可能的话,最好将所有内容都保留在标量中。
Generally though, you can't convert a vector v
to a scalar. 通常,虽然不能将向量v
转换为标量。 There may be more than one element in it, in which case the conversion isn't well defined. 其中可能包含多个元素,在这种情况下,转换的定义不明确。 What you can do, however, is index into the vector to extract one of its values. 但是,您可以做的是在向量中建立索引以提取其值之一。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.