In [1]:
import sys
print(sys.version)
At this point anything above python 3.5 should be ok.
In [2]:
import numpy as np
np.__version__
Out[2]:
In [3]:
import matplotlib as mpl
from matplotlib import pyplot as plt
mpl.__version__
Out[3]:
In [4]:
values = np.zeros((2,50))
size = values.shape
print(size)
for i in range(size[1]):
values[0,i] = i * 2
values[1,i] = np.sin(i / 2)
print(values)
In [5]:
np.save('np_file.npy', values)
np.savetxt('txt_file.txt', np.transpose(values))
In [6]:
values_from_text = np.loadtxt("txt_file.txt")
values_from_np = np.load("np_file.npy")
print(values_from_text[0,0] == values_from_np[0,0])
print(values_from_text)
In [ ]:
In [7]:
values = values_from_text
print(values.shape)
x_0 = values[0]
print(x_0)
x_1 = values[:,0]
print(x_1)
y_1 = values[:,1]
print(y_1)
In [8]:
fig = plt.figure()
plt.plot(x_1, y_1)
plt.show()
In [9]:
indices = [5,10, 15 ,20]
x = values[indices,0]
print(x)
y = values[indices,1]
print(y)
In [10]:
fig = plt.figure()
plt.plot(x, y)
plt.show()
In [11]:
indices = np.where(values[:,1] > -0.5)[0]
print("indices: ",indices)
x = values[indices,0]
print("x: ",x)
y = values[indices,1]
print("y: ",y)
In [12]:
fig = plt.figure()
plt.plot(x, y)
plt.show()
In [13]:
to_sort = np.random.rand(10)
print(to_sort)
In [14]:
to_sort.sort()
print(to_sort)
In [15]:
to_sort = np.random.rand(2,10)
print(to_sort)
In [16]:
to_sort.sort(axis=1)
print(to_sort)
In [17]:
to_sort = np.random.rand(3,10)
print(to_sort)
In [18]:
#investigate the axis we want to sort after
print("The axis to sort: \n",to_sort[1])
sort_indices = to_sort[1].argsort()
print("The indexes after the sort: \n",sort_indices)
#proceed the sort using the slicing method we just introduced
to_sort = to_sort[:,sort_indices]
print("The sorted full array:\n ",to_sort)