简体   繁体   English

如何使用ipython获取具有以下限制的二阶连接?

[英]How to get second-order connections using ipython with the following restrictions?

I have a connection from region1 to region6 (1->6) But I want to get second order connections. 我有一个从region1到region6的连接(1-> 6),但是我想获得二阶连接。 In other words: connections from region1 to region2 then region2 to region6. 换句话说:从区域1到区域2的连接,然后从区域2到区域6的连接。 (ie 1->2, 2->6) (即1-> 2、2-> 6)

I want to apply the following restriction: I don't want connections of the same region, such as region1 to region1 (ie 1->1 , 1->6) to be listed as a second-order connection. 我要应用以下限制:我不希望将同一区域(例如region1到region1)(即1-> 1,1-> 6)的连接列为第二级连接。

Note: Region1 to region6 is the same as region6 to region1. 注意:Region1到region6与region6到region1相同。 In addition I want connections to be listed in descending order. 另外,我希望连接按降序列出。 Therefore, if there is a second order connection that goes from region1 to region0 and then from region0 to region6 (1->0, 0->6). 因此,如果存在从区域1到区域0然后从区域0到区域6的二阶连接(1-> 0,0-> 6)。 I want it to instead be corrected to become region0 to region1 and then region0 to region6 (0->1, 0->6). 我希望它代替被校正为变得region0到REGION1然后region0到region6(0-> 1,0-> 6)。

Also, once all second order connections are performed I want it to be multiplied to get connection of region0 to region1 and then region0 to region6 (ie. 0->1, 0->6). 另外,一旦所有的二阶连接都执行完了,我希望将其乘以得到region0和region1的连接,然后是region0和region6的连接(即0-> 1,0-> 6)。

Once that's done, I want to compare it to the first order connection at the beginning of this question (1->6). 完成后,我想将其与该问题开始处的一阶连接进行比较(1-> 6)。 And then I want the program to take the higher value. 然后,我希望该程序具有更高的价值。 and save it. 并保存。

This is what I have so far: 这是我到目前为止的内容:

from itertools import combinations

a=print(list(combinations(range(7),2)))

print(list(product(a, repeat=2))

Output I get: [(0,1), (0,1)], [(0,1), (0,2)], [(0,1), (0,3)], etc. 输出我得到:[[0,1),(0,1)],[(0,1),(0,2)],[(0,1),(0,3)]等

This is not what I want 这不是我想要的

Any help would be appreciated. 任何帮助,将不胜感激。

You can start with itertools. 您可以从itertools开始。 The combinations module appears to be in sorted order, no repeated elements. 组合模块似乎已排序,没有重复的元素。

from itertools import combinations

print(list(combinations(range(7),2)))

Itertools are part of included packages in Python, and are excellent in iteratable areas. Itertools是Python随附的软件包的一部分,在可迭代领域非常出色。 Read https://docs.python.org/3/library/itertools.html 阅读https://docs.python.org/3/library/itertools.html

Beyond combinations is product, which is cartesian product, and permutations,that gives all possible orderings, no repeated elements. 组合之外是乘积(即笛卡尔乘积)和排列,这些排列给出所有可能的排序,没有重复的元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 获取嵌套字典中所有二阶键的列表 - Get list of all second-order keys in nested dictionary 使用 GEKKO(二阶微分方程)的估计参数 - Estimation parameters using GEKKO (a second-order differential equation) 使用 Python,我不知道如何计算给定 function 在此密度 function 中的非恒定速度的二阶 Lax 方案 - using Python, I do not know how to calculate the Second-order Lax scheme of the given function with non-constant velocity in this density function 文本中词语的二阶同时出现 - Second-order cooccurrence of terms in texts 如何以相同的步长将欧拉方法与二阶龙格库塔方法进行比较? - How to compare Euler's method to a second-Order Runge-Kutta Method at the same stepsize? 使用py2neo获取具有二阶连接的节点? - Using py2neo to get nodes with second order connections? 我如何让 Python 解决这个二阶非线性常微分方程? - How do I make Python solve this Second-order nonlinear ODE? Python:使用odeint求解二阶线性微分方程 - Python: use odeint to solve second-order linear differential equation 二阶ODE dopri5 python UserWarning:较大的nmax - Second-order ODE dopri5 python UserWarning: larger nmax Runge-Kutta四阶方法求解二阶ODES - Runge-Kutta 4th order method to solve second-order ODES
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM