コード例 #1
0
def my_kmax(R, k):
    N = len(R)
    f = np.ravel(R)
    #print(f)
    indices = np.array(heapq.nlargest(k, range(len(f)), f.__getitem__))
    j = np.mod(indices, N)
    i = np.floor(indices / N)
    #print(indices)
    return [i, j]
コード例 #2
0
def valueRotate(img, amount=0.5):
    """
    Rotate the values, wrapping around at the beginning
    """
    return np.mod(np.clip(img, 0.0, 1.0) + amount, 1.0)
コード例 #3
0
xb = x

count = 0
#xsave = [0]*steps
#save_As=[]
#save_distribution = []
WRITE("Starting simulation")

avalanche_sizes = []

start = time.time()
for i in range(steps):
    print('Step:', i)
    WRITE("Step: " + str(i))
    if np.mod(i, float(steps) / 100) == 0:  #
        dist = list(np.bincount(list(degree.flat)))
        x_axis = list(np.arange(0, int(np.max(degree) + 1)))
        save_frame(i, A, [x_axis, dist])

    #Particle addition

    add_site = np.random.randint(0, N - 1)

    x[add_site] = x[add_site] + 1

    WRITE("Starting avalanche processing")

    #Avalanche processing
    """
    degree = np.array(np.sum(A,0))