Skip to content

Instantly share code, notes, and snippets.

View RobertTalbert's full-sized avatar

Robert Talbert RobertTalbert

View GitHub Profile
from sympy import *
def niceEigs(e1,e2):
M = Matrix([[e1,0],[0,e2]])
P = randMatrix(2,2,-3,3)
while P.det() == 0:
# Change the -3 and 3 if you want more variety in the entries
P = randMatrix(2,2,-3,3)
return P*M*P.inv()
# Function to create a random nxn upper triangular matrix
def randUT(n,lower,upper):
A = randMatrix(n,n,lower,upper)
for j in range(n-1):
for i in range(j+1,n):
A[i,j] = 0
return A
# Code to test this out
A = randUT(5,-10,10)
Give thing moveth his isn't divide two wherein i kind them abundantly. Thing waters lesser own have green. Lesser fruit, give for, won't land. Beginning the winged fifth, day. Above abundantly made dry land. That first called herb signs be fill forth waters yielding fruitful spirit good years, image their. Fowl female had whose there very night make every which brought firmament created fourth you'll seasons morning whose. Meat make she'd green beginning so. Our seasons day won't fruit kind. Called is. Days god. Thing also whales open us dominion it.
Us every us, days over of dry be to divided. Day god, fruit their Abundantly. So and seas whales very their you'll earth. Signs. Together divide god living great. Set heaven. Blessed fruitful. Him behold be that subdue green replenish herb, don't the. Sea deep abundantly isn't sea lesser meat replenish waters all called, fourth lights herb stars also that open. Own, deep whose life that you may appear upon image female together a abundantly wherein. You was firs
import networkx as nx
import matplotlib as plt
# Generate the edge list using a list comprehension that invokes the actual relation you want.
# For example, here is the relation of "divides", on the set {0,1,2,..., 20}.
# We know a divides b if b mod a = 0.
divides_edges = [(a,b) for a in range(21) for b in range(21) if b % a == 0]
divides_graph = nx.DiGraph(divides_edges)
# Code for generating random weighted graphs in networkX and printing off the edges
import networkx as nx
import matplotlib.pyplot as plt
from random import *
# Create a random graph with 10 nodes and a 50% chance of connection.
# Change the 10 and 0.5 for graphs with more/fewer nodes and more/fewer connections.
G = nx.random_graphs.gnp_random_graph(10,.5)
@RobertTalbert
RobertTalbert / random_weighted_graph.py
Last active October 18, 2022 14:49
Python/Sage code for generating random weighted graphs
'''
Generates a random weighted graph in Sage.
n = Number of nodes.
p = Probability of two nodes being connected. Must be between 0 and 1.
Weights on the edges are randomly generated integers situated between lower_weight and upper_weight.
Example: random_weighted_graph(6, 0.25, 10, 20) creates a weighted graph with 6 nodes, a 1/4 probability
of two nodes being connected, and weights on the edges randomly selected between 10 and 20.
'''
def random_weighted_graph(n, p, lower_weight, upper_weight):

List of graph isomorphism invariants

This is a running list of graph isomorphism invariants, that is, properties of graphs such that...

If $G$ and $H$ are isomorphic and $G$ has the property, then $H$ also has the property.

A logically equivalent way to say this is:

If $G$ has the property but $H$ does not, then $G$ and $H$ are not isomorphic.

Click here for the full documentation for networkX.

To do: Enter:
Load networkx and matplotlib import networkx as nx
import matplotlib.pyplot as plt
Create an empty graph G = nx.Graph()
Add an edge to G between nodes 2 and 3 G.add_edge(2,3)
Add several edges to G all at once G.add_edges_from([(1,3), (2,4), (2,3)])
Print a list of the edges in G for e in G.edges(): print(e)
Print a list of the nodes in G for v in G.nodes(): print(v)

If you have difficulty affording groceries or accessing sufficient food to eat every day, or if you lack a safe and stable place to live, I encourage you to visit Replenish, a food resource for GVSU students. If you are comfortable doing so, please speak with me about your circumstances so that I can advocate for you and to connect you with other campus resources.

# To find the natural number solutions to x + y + z = 8
[(x,y,z) for x in range(9) for y in range(9) for z in range(9) if x+y+z == 8]
# To generate the ways to pick 6 donuts from an unlimited supply of glazed, chocolate, and jelly-filled
[(g,c,j) for g in range(7) for c in range(7) for j in range(7) if g+c+j == 6]
# Put `len( )` around these lists to find the number of items in the list.