In [2]:
#import numpy module
import numpy
import matplotlib.pyplot as plt
# create an array from 1 to 100
A = numpy.array(range(1,101))
#create a box plot
plt.boxplot(A)
#disply boxplot
plt.show()
In [3]:
# import modules
import numpy as np
import matplotlib.pyplot as plt
# create an array of random numbers
a = np.random.random(100)
#function to calculate mean and std
def calculateMeanAndStd(x):
info = []
info.append(np.mean(x))
info.append(np.std(x))
return info
#print mean and std dev
info = calculateMeanAndStd(a)
# mean,stdev lines in line graph
mean = [info[0] for x in range(101)]
stdev = [info[1] for x in range(101)]
# create line graph of data with
# blue dashes for points, blue squares for mean
# green tiangles for stdev
plt.plot(a,'b--',mean,'bs',stdev,'g^')
#write text in plot
plt.text(0.5,info[0]+0.02,r'Mean')
plt.text(0.3,info[1]+0.02,r'Stdev')
# show line graph
plt.show()
In [ ]:
# import modules
import numpy as np
import matplotlib.pyplot as plt
#array with 8000 random values
a = np.random.random(8000)
#reshape array into 20x20x20
a = np.reshape(a,(20,20,20))
#compute average of slices
avg_x = np.mean(a, axis=0)
avg_y = np.mean(a, axis=1)
avg_z = np.mean(a, axis=2)
# save images
plt.imshow(avg_x)
plt.savefig('xAvg.png')
plt.imshow(avg_y)
plt.savefig('yAvg.png')
plt.imshow(avg_z)
plt.savefig('zAvg.png')
In [ ]:
# import modules
import numpy as np
import matplotlib.pyplot as plt
#array with 100 uniform random values
a = np.random.randint(1,101,100)
#create a line graph
plt.plot(a)
# Open a file
f = open("data", "wb")
#write array to file
f.write(a)
# Close opend file
f.close()
#disply histogram
plt.show()
In [ ]:
# import modules
import numpy as np
import matplotlib.pyplot as plt
# Open a file and read floats
a = np.fromfile("data", dtype=int, count=-1, sep='')
# create a generator for intervals
g = [14*x for x in range(8)]
g[-1] += 2
#create a histogram
plt.hist(a,bins=g)
plt.xlabel('Interval')
plt.ylabel('Count')
#disply histogram
plt.show()
In [1]:
# import modules
import numpy as np
import matplotlib.pyplot as plt
# create an array of random numbers
a = np.random.random(100)
#function to calculate mean and std
def calculateMeanAndStd(x):
info = []
info.append(np.mean(x))
info.append(np.std(x))
return info
#print mean and std dev
info = calculateMeanAndStd(a)
# mean,stdev lines in line graph
mean = [info[0] for x in range(101)]
stdev = [info[1] for x in range(101)]
# create line graph of data with
# blue dashes for points, blue squares for mean
# green tiangles for stdev
plt.plot(a,'b--',mean,'bs',stdev,'g^')
#write text in plot
plt.text(0.5,info[0]+0.02,r'Mean')
plt.text(0.3,info[1]+0.02,r'Stdev')
# show line graph
plt.show()