Path: blob/master/loop_reshape_test_power.py
104 views
# demo of how power function can increase the unipolarity of a random distribution12# pass the exponent of the power function in the command line3# ex: 'python loop_reshape_test_power.py 1.3'45import matplotlib.pyplot as plt6import numpy as np7import random, time, os, sys89# get the exponent from passing parameter10exponent = float(sys.argv[1])1112N = 50 # number of columns in the distribution1314x_data = np.array(range(N))15y_data = np.array([random.random() for i in range(N)])16y_data_sum = np.sum(y_data)17y_data = y_data/y_data_sum1819fig = plt.figure()20ax = fig.add_subplot(111)21rects = ax.bar(x_data, y_data, align='center')22ax.set_xlim(-1, N)23ax.set_ylim(0.0, 1.0)24fig.canvas.draw()25fig.show()2627while True:28sys.stdout.write('+')29sys.stdout.flush()3031y_data = np.power(y_data, exponent) # the power function32y_data_sum = np.sum(y_data)33y_data = y_data/y_data_sum3435for i in range(N):36rects[i].set_height(y_data[i])37fig.canvas.draw()38fig.show()3940time.sleep(0.3)4142434445