<jupyter_start><jupyter_text><jupyter_code># exemples de structures finies de données
# chaîne de caractères
s = "Hello"
# booléen
a = True
b = False
b == (not a) # True
# entier
x = 3
# réel
y = 3.4
# classes
class RoadUser:
    def __init__(self, position, velocity):
        self.name = ''
        self.position = position        
        self.velocity = velocity

    def move(self, deltaT):
        self.position += deltaT*self.velocity

    def getType(self):
        return 'User'

    def __str__(self):
        return '{} @ {}'.format(self.getType(), self.position)

    def draw(self):
        pass

class PassengerVehicle(RoadUser):
    def getType(self):
        return 'Véhicule'

class Pedestrian(RoadUser):
    def getType(self):
        return 'Piéton'

class Cyclist(RoadUser):
    def getType(self):
        return 'Cycliste'

roadUsers = [PassengerVehicle(1, 5.),
             Pedestrian(10, 1.),
             Cyclist(15, 2.)]

for r in roadUsers:
    print(r)
# exemples de structures indexées de données
# listes
l = [3,4]
m = list(range(10))
# ensemble
s = set(range(10))
# matrices etc.
import numpy as np
m = np.zeros((5,6))
print(m)
m = np.random.random_sample(25).reshape(5, 5)
print(m)
# dictionnaire
comptages = {'autos': 12, 'cyclistes': 45, 'piétons': 23}
# exemples de structures récursives
%matplotlib inline
#%config InlineBackend.figure_format = 'svg'
import matplotlib.pyplot as plt
import networkx as nx
import osmnx as ox
#ox.plot_graph(ox.graph_from_place('Modena, Italy'))
G = ox.graph_from_address('2900 Bd Edouard Montpetit, Montreal, QC', network_type='drive')
ox.plot_graph(G)
ox.basic_stats(G)
#ox.extended_stats(G, bc=True)
# G.node
dict(G.adjacency())[29784055]<jupyter_output><empty_output><jupyter_text>Algorithmes vus en coursD'autres algorithmes classiques sont décrits dans des ressources extérieures:* Wikipedia: https://en.wikipedia.org/wiki/List_of_algorithms en particulier * listes: https://en.wikipedia.org/wiki/List_of_algorithmsSequence_algorithms dont les tris https://en.wikipedia.org/wiki/List_of_algorithmsSequence_sorting * regroupement ("clustering") https://en.wikipedia.org/wiki/Data_clustering<jupyter_code>import random
# données d'entrée
vitesses = [random.uniform(45,55) for x in range(10000)]
# algo 1: quelle est la sortie?
x = vitesses

somme = 0
i = 0
while i < len(x):
    somme = somme + x[i]
    i = i + 1
print(somme/len(x))
# algorithme plus petit
a = np.random.randint(0,100,10)
print('Entree:', a)

plusPetit = None

# continuer

print('Plus petit:', plusPetit) 
# tri
print('Entree:', a)

def plusPetit(a):
    return a[0]

sortie = []

# continuer

print('Liste triee:', sortie)
# algorithme factorielle
def Factorielle(N):
    M=1
    F=1
    while M != N:
        M=M+1
        F=F*M
        print("F={},M={}".format(F, M))
    return F

N = int(input('Entrer un entier positif: '))
print('Résultat de factorielle de {}: {}'.format(N, Factorielle(N)))
# calculer de distances
coordonnees = {'Montréal': [611982, 5039496], # meme zones UTM 18T
              'Trois-Rivières': [688507, 5135853],
              'Mont-Tremblant': [530908, 5107088],
              'Gatineau': [449203, 5036850]}

# forme alternative
np.array(list(coordonnees.values()))

# continuer<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13614163614163613, 'fraction_numerical': 0.036019536019536016, 'mean_word_length': 3.8191176470588237, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 9, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '68965', 'license': 'MIT', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1197, 'n_words': 288, 'path': '03-traitement-donnees.ipynb', 'repo_name': 'nsaunier/CIV8760', 'size': '3276'}