从某些向量创建价值对

发布于 2025-02-07 04:04:55 字数 727 浏览 1 评论 0原文

假设我们有一对类似以下的对,并且每对都带有一个附加的值。毫无疑问,对(1,2)2.5。 还有另一组p1代表一组人。每个人都连接到一组对。例如,对于p1 中的p,它们的关联对是p1_pairs(即[(1,2),(1,1,7),(2) )]



Pairs  = [(1, 2), (1, 7), (2, 3), (2, 5),(3, 4), (3, 5), (4, 1), (4, 5), (5, 2)]
Values = [ 2.5,    4.1,    7.4,    5.6,   2.8,    3.7,    6.9,     0.2,    3.2 ]

P1 = ['p','q']
p1_pairs = [   [(1, 2), (1, 7), (2, 3)], 
               [(1, 2), (2, 3), (2, 5) ,(5, 2)] 
           ]

, 3

。 1,2)] = 2.5 和person_values ['q',(2,3)] = 7.4。 换句话说,person_values将通过p1p1_pairs 索引索引,然后根据其value将相应值分配给它们。

Suppose we have a set of pair like the following, and each pair comes with a value attached to it. For isntance the value of pair (1,2) is 2.5.
There are another set p1 which represent a set of persons. Each person connected to set of pairs. For instance, for p in p1 their associated pairs are the first elemenst of p1_pairs (i.e. [(1, 2), (1, 7), (2, 3)].



Pairs  = [(1, 2), (1, 7), (2, 3), (2, 5),(3, 4), (3, 5), (4, 1), (4, 5), (5, 2)]
Values = [ 2.5,    4.1,    7.4,    5.6,   2.8,    3.7,    6.9,     0.2,    3.2 ]

P1 = ['p','q']
p1_pairs = [   [(1, 2), (1, 7), (2, 3)], 
               [(1, 2), (2, 3), (2, 5) ,(5, 2)] 
           ]

The question is, how to bulid up a parameter person_values such that it return the value of the associated pairs?

For instance person_values['p',(1, 2)] = 2.5 and person_values['q',(2, 3)] = 7.4.
In other words person_values will be indexed over elemets of p1 and p1_pairs and then assign s the corresponding values to them based on their values

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

や莫失莫忘 2025-02-14 04:04:55

如果我正确理解您的问题,您想要这个:

julia> pv = Dict( Pairs .=> Values);

julia> [getindex.(Ref(pv), vals) for vals in p1_pairs]
2-element Vector{Vector{Float64}}:
 [2.5, 4.1, 7.4]
 [2.5, 7.4, 5.6, 3.2]

If I correctly understood your question you want this:

julia> pv = Dict( Pairs .=> Values);

julia> [getindex.(Ref(pv), vals) for vals in p1_pairs]
2-element Vector{Vector{Float64}}:
 [2.5, 4.1, 7.4]
 [2.5, 7.4, 5.6, 3.2]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文