In [1]:
import numpy
In [5]:
numpy.loadtxt(fname='data/data/weather-01.csv',delimiter = ',')
Out[5]:
In [3]:
!ls data
In [6]:
weight_kg = 55
In [7]:
print (weight_kg)
In [8]:
print('Weight in pounds: ', weight_kg * 2.2)
In [9]:
print ('New weight: ', weight_kg * 2.2)
In [11]:
%whos
In [12]:
data = numpy.loadtxt(fname='data/data/weather-01.csv',delimiter = ',')
In [13]:
print (data)
In [14]:
print (type(data))
In [15]:
%whos
In [16]:
# Finding out the data type
print (data.dtype)
In [17]:
# Finf out the shape
print (data.shape)
In [18]:
# This is 60 rows * 40 columns
In [19]:
# Getting a single number out of the array
In [20]:
print ("First value in data: ", data [0,0])
In [21]:
print('A middle value: ', data[30,20])
In [22]:
# Lets get the first 10 columns for the first 4 rows
print(data[0:4, 0:10])
In [23]:
# Lets get the first 10 columns for the first 4 rows
print(data[0:4, 0:10])
In [24]:
# 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 [25]:
# We don't need to start slicing at 0
In [26]:
# We don't need to start slicing at 0
In [27]:
# We don't need to start slicing at 0
print (data[5:10, 7:15])
In [28]:
# We don't even need to include the UPPER and LOWER bounds
smallchunk = data [:3, 36:]
In [29]:
# We don't even need to include the UPPER and LOWER bounds
smallchunk = data [:3, 36:]
In [30]:
# We don't even need to include the UPPER and LOWER bounds
smallchunk = data [:3, 36:]
print(smallchunk)
In [31]:
#Arithmetic on arrays
doublesmallchunk = smallchunk * 2.0
In [32]:
print(doublesmallchunk)
In [33]:
triplesmallchunk = smallchunk + doublesmallchunk
In [34]:
print (triplesmallchunk)
In [35]:
print (numpy.mean(data))
In [36]:
print (numpy.min(data))
In [37]:
# Get a set of data for the first station
In [38]:
# Get a set of data for the first station
In [39]:
# Get a set of data for the first station
station_0 = data [0,:]
In [40]:
print(numpy.max(station_0))
In [41]:
# We don't need to create 'temporary' array slices
In [42]:
# We don't need to create 'temporary' array slices
In [43]:
# We don't need to create 'temporary' array slices
# We can refere to what we call array axes
In [45]:
# axis = 0 gets the mean Down each column, so the mean temperature
# for recording period
print (numpy.mean(data,axis = 0))
In [46]:
# axis = 0 gets the mean Down each column, so the mean temperature
# for each station for all the periods
print (numpy.mean(data,axis = 1))
In [47]:
# Do some simple visualisations
In [48]:
import matplotlib.pyplot
In [49]:
%matplotlib inline
In [50]:
image = matplotlib.pyplot.imshow(data)
In [51]:
# Let's look at the average temperature over time
avg_temperature = numpy.mean(data,axis = 0)
In [52]:
avg_plot = matplotlib.pyplot.plot(avg_temperature)
In [53]:
Task:
In [55]:
# Task
* Produce maximum and minimum plots of this data
* What do you think?
In [56]:
max_temperature = numpy.max(data,axis = 0)
min_temperature = numpy.min(data,axis = 0)
In [58]:
avg_plot = matplotlib.pyplot.plot(avg_temperature)
max_plot = matplotlib.pyplot.plot(max_temperature)
min_plot = matplotlib.pyplot.plot(min_temperature)
In [ ]: