100% de satisfacción garantizada Inmediatamente disponible después del pago Tanto en línea como en PDF No estas atado a nada 4.2 TrustPilot
logo-home
Resumen

Network Science - Samenvatting + uitwerkingen colleges

Puntuación
-
Vendido
-
Páginas
36
Subido en
18-01-2024
Escrito en
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.

Mostrar más Leer menos
Institución
Grado











Ups! No podemos cargar tu documento ahora. Inténtalo de nuevo o contacta con soporte.

Escuela, estudio y materia

Institución
Estudio
Grado

Información del documento

Subido en
18 de enero de 2024
Número de páginas
36
Escrito en
2023/2024
Tipo
Resumen

Temas

Vista previa del contenido

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
$12.57
Accede al documento completo:

100% de satisfacción garantizada
Inmediatamente disponible después del pago
Tanto en línea como en PDF
No estas atado a nada

Conoce al vendedor

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
koenverhoeff Universiteit van Amsterdam
Seguir Necesitas iniciar sesión para seguir a otros usuarios o asignaturas
Vendido
23
Miembro desde
5 año
Número de seguidores
12
Documentos
6
Última venta
1 mes hace

0.0

0 reseñas

5
0
4
0
3
0
2
0
1
0

Recientemente visto por ti

Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes