转换为向量
这似乎是一件非常简单的事情,但是相信与否我的Google搜索没有给我带任何地方。我希望能够将集合转换为向量。我已经尝试了以下内容:
sett=Set{Int64}([1,2,3])
vecc=convert(Vector{Int64},sett)
但是看来朱莉娅不知道该如何进行这些转换。
我能做的一件明显的事情是使用综合,例如
vecc=[el for el in sett]
,没有更优雅的方式吗?
提前欢呼。
This seems like a really easy thing, but believe it or not my google search hasn't brought me anywhere. I want to be able to convert a set to a vector. I have tried the following:
sett=Set{Int64}([1,2,3])
vecc=convert(Vector{Int64},sett)
but it appears Julia doesn't know how to do these conversions.
One obvious thing I can do is using comprehensions e.g.
vecc=[el for el in sett]
but is there not a more elegant way?
Cheers in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从性能的角度来看,分裂可能是有问题的。而是使用
Splatting can be problematic from a performance perspective. Instead, use
您可以使用 splat ocerator 操作员:
虽然,但是, (对我来说)比使用列表理解更优雅,即使有相对较小的收藏(由于每个元素至少需要一个分配!),也应该避免出现绩效问题的裂口。
因此,如果担心性能,您绝对应该使用
collect()
或坚持列表理解:collect> collect(set)
[i in set in set] in in set] < /code>
[set ...]
You can use the splat operator :
Though, while this is (to me) more elegant than using list comprehension, one should avoid splatting for performance concerns, even with relatively small collections (as it requires at least one allocation per element!).
So if concerned about performance, you should definitely use
collect()
or stick with list comprehension :collect(set)
[i for i in set]
[set...]