100% tevredenheidsgarantie Direct beschikbaar na je betaling Lees online óf als PDF Geen vaste maandelijkse kosten 4.2 TrustPilot
logo-home
Samenvatting

Network Science - Samenvatting + uitwerkingen colleges

Beoordeling
-
Verkocht
-
Pagina's
36
Geüpload op
18-01-2024
Geschreven in
2023/2024

Alles wat je moet weten voor het vak Network Science (en Python in het algemeen). Dit bestand bestaat uit zowel een samenvatting als de meest belangrijke concepten (met uitwerkingen) die gehanteerd worden in het vak network science. Het fijne aan dit bestand is dat het uitleg geeft bij de gegeven codes. Veel van deze codes/theorieën kwamen terug in het tentamen.

Meer zien Lees minder











Oeps! We kunnen je document nu niet laden. Probeer het nog eens of neem contact op met support.

Documentinformatie

Geüpload op
18 januari 2024
Aantal pagina's
36
Geschreven in
2023/2024
Type
Samenvatting

Onderwerpen

Voorbeeld van de inhoud

network-science

January 18, 2024


1 Summary
[1]: %matplotlib inline
import networkx as nx
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from pandas import DataFrame
import scipy
from nose.tools import assert_equal
from numpy.testing import assert_almost_equal, assert_array_almost_equal
import random
from collections import Counter


1.1 Python Data Types
Float: real numbers
Int: integer numbers
Str: string
Bool: True, False

1.1.1 List vs. tuple vs. set vs. dict
Lists[] are used to store multiple items in a single variable. List items are ordered, changeable and
allow duplicate values.
Sets{} are used to store multiple items in a single variable. A set is a collection which is unordered,
unchangeable* and do not allow duplicate values.
Frozenset is just an immutable version of a Python set object. While elements of a set can be
modified at any time, elements of the frozen set remain the same after creation. Due to this, frozen
sets can be used as keys in Dictionary or as elements of another set.
*Note: Set items are unchangeable, but you can remove items and add new items.
Tuples() are used to store multiple items in a single variable. A tuple is a collection which is
ordered, unchangeable and allow duplicate values



1

, Dict{} are used to store data values in key:value pairs. A dictionary is a collection which is ordered*,
changeable and do not allow duplicate values.
*Note: As of Python version 3.7, dictionaries are ordered. In Python 3.6 and earlier, dictionaries
are unordered.

1.2 Python Objects/Classes
Almost everything in Python is an object, with its properties and methods. Objects get their
variables and functions from classes. Classes are essentially a template to create your objects. A
Class is like an object constructor, or a “blueprint” for creating objects.
[2]: class MyClass:
x = 5

y = MyClass()
print(y.x)

5

1.3 Subsetting / List slicing
[3]: names = ["Jan", "Piet", "Klaas", "Kees", "Anne"]
# index 4 is uitgesloten
print(names[2:4], names[3:])

['Klaas', 'Kees'] ['Kees', 'Anne']

1.4 For-loops
[4]: # Voeg een lijst toe van de gewichten
weights = [70, 80, 90, 75, 65]

# Maak een lege lijst voor de namen EN gewichten
name_weight_list = []

# Voeg willekeurige namen en gewichten toe aan de lijst
for i in range(5):
name = random.choice(names)
weight = random.choice(weights)
name_weight_list.append((name, weight)) # Tuples (Een paartje)

# Als list comprehensie:
# name_weight_list = [(random.choice(names), random.choice(weights)) for i in␣
↪range(5)]

print(name_weight_list)

[('Kees', 80), ('Piet', 75), ('Piet', 75), ('Anne', 70), ('Klaas', 80)]



2

, 1.5 Conditionals
1.5.1 if-statement (in loop)

[5]: # Om ervoor te zorgen dat elke naam slechts één keer voorkomt in de lijst:
chosen_names = []

name_weight_list = []

# Voeg willekeurige namen en gewichten toe aan de lijst
for i in range(5):
# Kies een naam die nog niet is gekozen
name = random.choice([name for name in names if name not in chosen_names])
# Voeg de gekozen naam toe aan de lijst van gekozen namen
chosen_names.append(name)
weight = random.choice(weights)
name_weight_list.append((name, weight))

print(name_weight_list)

[('Anne', 70), ('Kees', 90), ('Piet', 65), ('Jan', 75), ('Klaas', 65)]

1.5.2 elif-statement
[6]: number_of_apples = 3

if number_of_apples < 1:
print('You have no apples')
elif number_of_apples == 1:
print('You have one apple')
elif number_of_apples < 4:
print('You have a few apples')
else:
print('You have many apples!')

You have a few apples

1.6 Functions
A function is a piece of reusable code, aimed at solving a particular task. You can call functions
instead of having to write code yourself.
output = function_name(input)

[87]: # Handige functies:
# len()
# max()
# min()
# round()



3

, # sorted()
dieren = ['hond', 'kat', 'paard', 'vogel']
aantal_dieren = len(dieren)

getallen = [5, 2, 8, 1, 3]
gesorteerde_getallen_aflopend = sorted(getallen, reverse=True)

print(gesorteerde_getallen_aflopend, aantal_dieren)
type(aantal_dieren)

[8, 5, 3, 2, 1] 4

[87]: int


1.6.1 Methods
Methods are functions that belong to specific objects.
[8]: # Handige methodes
# .index()
# .append() end of the list
# .insert() specific place
# .remove("appel") of # del fruit[0]
fruit = ["appel", "banaan", "kiwi"]
fruit.insert(1, "peer")
fruit

[8]: ['appel', 'peer', 'banaan', 'kiwi']


1.6.2 Iterable
An iterable is any Python object capable of returning its members one at a time, permitting it to
be iterated over in a for-loop. Familiar examples of iterables include lists, dicts, and strings.

1.7 Comprehensions
1.7.1 List comprehension
List comprehension offers a shorter syntax when you want to create a new list based on the values
of an existing list.
Components: - Output expression - Iterator variable (represent members of iterable) - Iterable

[9]: # [ output expression for iterator variable in iterable if predicate expression␣
↪]



# Based on a list of fruits, you want a new list, containing only the fruits␣
↪with the letter "a" in the name. Without list comprehension you will have to␣

↪write a for statement with a conditional test inside:




4
€10,39
Krijg toegang tot het volledige document:

100% tevredenheidsgarantie
Direct beschikbaar na je betaling
Lees online óf als PDF
Geen vaste maandelijkse kosten

Maak kennis met de verkoper

Seller avatar
De reputatie van een verkoper is gebaseerd op het aantal documenten dat iemand tegen betaling verkocht heeft en de beoordelingen die voor die items ontvangen zijn. Er zijn drie niveau’s te onderscheiden: brons, zilver en goud. Hoe beter de reputatie, hoe meer de kwaliteit van zijn of haar werk te vertrouwen is.
koenverhoeff Universiteit van Amsterdam
Bekijk profiel
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
23
Lid sinds
5 jaar
Aantal volgers
12
Documenten
6
Laatst verkocht
1 maand geleden

0,0

0 beoordelingen

5
0
4
0
3
0
2
0
1
0

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Veelgestelde vragen