I want to create a rectangular square lattice using GraphViz where all nodes are connected in both directions to their neighbors. The problem is, that if I use the terminal comand
osage -Tpng graph.gv > graph.png
to create this rectangular graph, the first and the last nodes are swapped. I checked all the links between the nodes and changing the position of node 0 and node 15 would yield the desired structure with correct connections. Here a small example of the resulting graph:
This issue also remains if I cancel all node-connections and only use the simple graph.gv file:
graph G {
0;
1;
2;
3;
4;
5;
6;
7;
8;
}
Up to 6 nodes, the node ordering is correct without any swap. For any higher node number, it gets mixed. I would expect osage to automatically correct the wrong ordering while adding the links between the nodes. But adding links does not change anything in the wrong ordering. I have also looked at possible attributes but could not find anything which would solve the problem.
Has anybody experienced a similar problem and can help me with this issue? Thanks in advance!
This seems to have been fixed. This input
digraph grid {
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
0 -> 1
0 -> 4
1 -> 0
1 -> 2
1 -> 5
2 -> 1
2 -> 3
2 -> 6
3 -> 2
3 -> 7
4 -> 5
4 -> 0
4 -> 8
5 -> 4
5 -> 6
5 -> 1
5 -> 9
6 -> 5
6 -> 7
6 -> 2
6 -> 10
7 -> 6
7 -> 3
7 -> 11
8 -> 9
8 -> 4
8 -> 12
9 -> 8
9 -> 10
9 -> 5
9 -> 13
10 -> 9
10 -> 11
10 -> 6
10 -> 14
11 -> 10
11 -> 7
11 -> 15
12 -> 13
12 -> 8
13 -> 12
13 -> 14
13 -> 9
14 -> 13
14 -> 15
14 -> 10
15 -> 14
15 -> 11
}
And osage from Graphviz version 2.43.0 gives:
Related
11 -> 3
10 -> 3.1
9 -> 3.333
8 -> 3.5
7 -> 3.7142857142857
6 -> 4
5 -> 4.4
4 -> 5
3 -> 5.666
2 -> 7
1 -> 10
Basically I'm trying to reverse engineer a function for calculating Xp awarded to a player. The first number is what you feed into the function, while the second number is what it returns. After visualizing the returned numbers I figured out that they're an inverse exponential, but I've had no luck in implementing them in lua.
for n = 1, 11 do
local xp = math.floor(10 * n^.5)/n
print(n, xp)
end
Output:
1 10
2 7
3 5.6666666666667
4 5
5 4.4
6 4
7 3.7142857142857
8 3.5
9 3.3333333333333
10 3.1
11 3
I am trying to create an index for a data frame. Each team playing has its own row, but I would like to add a column to use as an index so that the first two teams have the index 'Game 0', the next two teams have the index 'Game 1' until the length of half the list. In python the code would look as follows:
for i in range(0,int(len(teams)/2)):
gamenumber.append('Game '+str(i))
gamenumber.append('Game '+str(i))
I am unfamiliar with R so any help would be appreciated!
This will give you a list of paired index numbers:
> teams=1:100
> data.frame("Games"=sort(c(1:(length(teams)/2), 1:(length(teams)/2))))
Games
1 1
2 1
3 2
4 2
5 3
6 3
7 4
8 4
9 5
10 5
11 6
12 6
13 7
14 7
15 8
16 8
17 9
18 9
19 10
20 10 #etc.
Assuming teams is a data.frame with an even number of rows:
rep(1:(nrow(teams)/2), each=2)
How do i find an element wise product of two tensors? Both my tensors are of the same dimension and i want to find their product?
q
1 2 3
2 4 6
w
1 2 3
2 4 6
It should yield:
1 4 9
4 16 36
You can do this by using cmul.
th> torch.cmul(q,w)
1 4 9
4 16 36
As a side note:
q:cmul(w): will multiply them and store the value back into q,
z=torch.cmul(q,w): will multiply them and return a new tensor which will be stored in z.
I have an array of Cartesian coordinates produced from polars in a usual way:
for k in range(0, Phi_term):
for j in range(0, R_term):
X[k,j] = R[j]*np.cos(phi[k]);
Y[k,j] = R[j]*np.sin(phi[k]);
The problem is that the zeroth element of such an array corresponds to the origin of the polar circle. I would like to have an array of the same elements but starting in the top right corner. For example, elements in the current array distribute in the following way (for the upper half):
11 10 9 6 7 8
14 13 12 3 4 5
17 16 15 0 1 2
(imagine it's a circle). What I want to get is the grid starting with the zeroth element:
0 1 2 3 4 5
6 7 8 9 10 11
12 13 14 15 16 17
though preserving the values, i.e. the value of the 11th element of the initial array is now the value of the 0th element of the new array.
Is there any smart way to perform such a transformation in numpy?
def quasiCartesianOrder(arr, R_term, Phi_term):
# deal with odd phi count by starting from top of top spike.
rhsOddOffset = 0
if Phi_term % 2 == 1:
rhsOddOffset = R_term
for r in xrange(0, R_term):
yield (Phi_term + 1)/2 * R_term - r - 1
# 'rectangular' section, starting down 11 o'clock and up 1 o'clock.
phiBaseLeft = Phi_term / 2 + rhsOddOffset/R_term
phiBaseRight = Phi_term / 2
for phiLine in xrange(0, Phi_term / 2):
# down 11
base = (phiBaseLeft + phiLine) * R_term - 1
for idx in xrange(base + R_term, base, -1):
yield idx
# up 1
base = (phiBaseRight - phiLine ) * R_term
for idx in xrange(base - R_term, base):
yield idx
Behaviour:
11
10
9
14 13 12 6 7 8
17 16 15 3 4 5
20 19 18 0 1 2
Becomes
0
1
2
3 4 5 6 7 8
9 10 11 12 13 14
15 16 17 18 19 20
Result
11 10 9 14 13 12 6 7 8 17 16 15 3 4 5 20 19 18 0 1 2
The style is a generator, so that you can iterate. If you just want the indices themselves, call list with the returned generator, and you should be able to use that with numpy's index arrays stuff.
A bridge in a graph means if we remove it the graph will be disconnected !
so i want to know if there is way to find all bridges in a graph :
here is an example :
input
12 15
1 2
1 3
2 4
2 5
3 5
4 6
6 7
6 10
6 11
7 8
8 9
8 10
9 10
10 11
11 12
Output :
2 4
4 6
11 12
PLEASE DO NOT GIVE ME THE SOLUTION JUST A HINT !
Thanks
If you have the visiting number vn[v] and low number low[v] for each vertex v in graph G, then you can find if an edge is bridge of not (while unwinding the dfs recursive calls) using the following condition
if (low[w] > vn[v]) then (v,w) is a bridge