Michaël Defferrard, PhD student, EPFL LTS2
You can list your environments:
!conda info --envs
# conda environments: # test /home/michael/.conda/envs/test root * /usr
List the packages in an environment:
!conda list -n test
# packages in environment at /home/michael/.conda/envs/test: # curl 7.54.1 0 expat 2.1.0 0 git 2.14.2 0 conda-forge krb5 1.13.2 0 libiconv 1.14 4 conda-forge libssh2 1.8.0 0 openssl 1.0.2l 0 zlib 1.2.8 3 conda-forge
Install packages:
!conda install -n test git
Fetching package metadata ........... Solving package specifications: . # All requested packages already installed. # packages in environment at /home/michael/.conda/envs/test: # git 2.14.2 0 conda-forge
Want to know more? Look at the conda user guide.
Below are very basic examples of Python code. Want to learn more? Look at the Python Tutorial.
if 1 == 1:
print('hello')
hello
for i in range(5):
print(i)
0 1 2 3 4
a = 4
while a > 2:
print(a)
a -= 1
4 3
Lists are mutable, i.e. we can change the objects they store.
a = [1, 2, 'hello', 3.2]
print(a)
a[2] = 'world'
print(a)
[1, 2, 'hello', 3.2] [1, 2, 'world', 3.2]
Tuples are not mutable.
(1, 2, 'hello')
(1, 2, 'hello')
Sets contain unique values.
a = {1, 2, 3, 3, 4}
print(a)
print(a.intersection({2, 4, 6}))
{1, 2, 3, 4} {2, 4}
Dictionaries map keys to values.
a = {'one': 1, 'two': 2, 'three': 3}
a['two']
2
def add(a, b):
return a + b
add(1, 4)
5
class A:
d = 10
def add(self, c):
return self.d + c
a = A()
a.add(20)
30
class B(A):
def sub(self, c):
return self.d - c
b = B()
print(b.add(20))
print(b.sub(20))
30 -10
x = 1
x = 'abc'
x
'abc'
add('hel', 'lo')
'hello'
add([1, 2], [3, 4, 5])
[1, 2, 3, 4, 5]
print(int('120') + 10)
print(str(120) + ' items')
130 120 items
Jupyter notebooks allow to mix text, math, code, and results (numerical or figures) in a single document.
A list:
Text in a paragraph. Text can be italic, bold, verbatim
. We can define hyperlinks.
A numbered list:
Some inline math: $x = \frac12$
Some display math: $$f(x) = \frac{e^{-x}}{4}$$
20 / 100 * 30
6.0
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
y = np.random.uniform(size=100)
plt.plot(y);
conda install git
.Two kinds of users:
git pull
before every lab. Do not modify the content of the folder. That is like your inbox, you only copy files from there and modify them outside.git branch ass1_my_solution
git checkout ass1_my_solution
git checkout master
and get new stuff from the TAs with git pull
. Again, you should never modify master (you could do it locally, but only the TAs have write access to the github repo).Those who want to backup or share their work on github.
git remote add my_repo git@github.com:username/ntds_2017.git
git push -u my_repo ass1_my_solution
.We'll come back to this when we'll start working on the projects.
Below are the basic packages used for scientific computing and data science. We'll introduce them as needed during the following tutorials.
Want to learn more? Look at the Scipy Lecture Notes.
Finally, the below packages will be useful to work with networks and graphs.