import numpy
In [26]:
import numpy
In [27]:
numpy.loadtxt(fname='data/weather-01.csv', delimiter = ',')
Out[27]:
In [28]:
numpy.loadtxt(fname='data/weather-01.csv', delimiter = ',')
Out[28]:
In [29]:
weight_kg = 55
In [30]:
print (weight_kg)
In [31]:
print ('Weight in pounds: ', weight_kg * 2.2)
In [32]:
weight_kg = 57.5
In [33]:
print ('New weight: ', weight_kg * 2.2)
In [34]:
%whos
In [35]:
data = numpy.loadtxt(fname='data/weather-01.csv', delimiter = ',')
In [36]:
print (data)
In [37]:
print (type(data))
In [38]:
%whos
In [39]:
# Finding out the data type
print (data.dtype)
In [40]:
# Find out the shape
print (data.shape)
In [41]:
# This is 60 rows * 40 columns
In [42]:
# Getting a single number out of the array
print ("First value in data: ", data [0, 0])
In [43]:
print ('A middle vaule: ', data[30, 20])
In [44]:
# Lets get the first 10 columns for the first 4 rows
print (data[0:4, 0:10])
# Start at index 0 and go up to BUT NOT INCLUDING index 4
In [45]:
# We don't need to start slicing at 0
print (data[5:10, 7:15])
In [46]:
# We don't even need to include the UPPER and LOWER bounds
smallchunk = data [:3, 36:]
print (smallchunk)
In [47]:
# We don't even need to include the UPPER and LOWER bounds
smallchunk =data [:3, 36:]
print (smallchunk)
In [48]:
# Arithmetic on arrays
doublesmallchunk = smallchunk * 2.0
In [49]:
print (doublesmallchunk)
In [50]:
triplesmallchunk = smallchunk + doublesmallchunk
In [51]:
print (triplesmallchunk)
In [52]:
print (numpy.mean(data))
In [53]:
print (numpy.min(data))
In [54]:
# Get a set of data fro the first station
station_0 = data [0, :]
In [55]:
print (numpy.max(station_0))
In [56]:
# We don't need to create ' tempory' array slices
# We can refer to what we call array axes
In [57]:
# axis = 0 gets the mean DOWN each column, so the mean temperature
# for each recording period
print (numpy.mean(data, axis = 0))
In [58]:
# axis = 0 gets the mean ACROSSS each row, so the mean temperature
# for each station for all periods
print (numpy.mean(data, axis = 1))
In [59]:
# Do some simple visualisations
In [60]:
import matplotlib.pyplot
In [61]:
%matplotlib inline
In [62]:
image = matplotlib.pyplot.imshow(data)
In [63]:
# Let's take a look at the average temperature over time
avg_temperature = numpy.mean(data, axis = 0)
In [64]:
avg_plot = matplotlib.pyplot.plot(avg_temperature)
In [65]:
avg_plot = matplotlib.pyplot.plot(avg_temperature)
max_plot = matplotlib.pyplot.plot(max_temperature)
min_plot = matplotlib.pyplot.plot(min_temperature)
In [66]:
max_temperature = numpy.max(data, axis = 0)
In [67]:
min_temperature = numpy.min(data, axis = 0)
In [68]:
avg_plot = matplotlib.pyplot.plot(avg_temperature)
max_plot = matplotlib.pyplot.plot(max_temperature)
min_plot = matplotlib.pyplot.plot(min_temperature)
In [ ]: