- Deve ser possível criar um Perceptron::
>>> from perceptron import Perceptron >>> perceptron = Perceptron()
- O w deve ser construido corretamente::
>>> x = [[1,2], [6,7], [1,1], [1,2], [7, 7]]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def max_subarray_sum(iterator): | |
iterable = iter(iterator) | |
try: | |
next_element = next(iterable) | |
except StopIteration: | |
return Exception('Impossible get max sum of empty sequence') | |
def max_iter(current_sum, max_sum): | |
try: | |
next_element = next(iterable) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter | |
def find_odds(seq): | |
return [k for k, v in Counter(seq).items() if v % 2 == 1] | |
print(find_odds([20, 1, -1, 2, -2, 3, 3, 5, 5, 1, 2, 4, 20, 4, -1, -2, 5])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_max(iterable): | |
lst = list(iterable) | |
n = len(lst) | |
if n == 0: | |
raise Exception('Not possible finding max of empty') | |
def find_iter(current_max, i): | |
if i == n: | |
return current_max |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from __future__ import absolute_import, unicode_literals | |
def find_max(iterable): | |
lst = list(iterable) | |
if len(lst) == 0: | |
raise Exception('Not possible finding max of empty') | |
def find_iter(current_max): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from __future__ import absolute_import, unicode_literals | |
def find_max(iterable): | |
iterator = iter(iterable) | |
def find_iter(current_max): | |
try: | |
current = next(iterator) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
declare -a files=( | |
'/var/lib/pgsql/data/postgresql.conf' | |
'/etc/foreman/settings.yaml' | |
'/etc/foreman-proxy/settings.yml' | |
'/etc/puppet/puppet.conf' | |
'/etc/dhcp/dhcpd.conf' | |
'/etc/named.conf' | |
'/etc/xinetd.d/tftp' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Observaçoes: | |
# A palavra reservada with produz um gerenciador de contexto que irá fechar o arquivo | |
# para vc, então não precisa chamar o método close | |
# Veremos mais sobre o assunto em no curso Python para Quem Sabe Python ;) | |
# Ao escrever em modo string, melhor explicitar o encoding. | |
# Pode ser que ele use o encoding padrão do sistema e ao | |
# escrever em um computador e ler em outro de problema | |
with open('/tmp/fn', 'w', encoding='utf8') as fn: | |
fn.write('Café') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dct = {'gripe': set(('tosse', 'febre')), 'dengue': set(('tosse', 'dor de cabeça'))} | |
sintomas_paciente=set(('tosse', 'febre')) | |
doencas_probabilidade={doenca: (sintomas_paciente & sintomas_doenca) for doenca,sintomas_doenca in dct.items() } | |
print(doencas_probabilidade) | |
print(sorted([(len(sintomas), doenca) for doenca,sintomas in doencas_probabilidade.items()])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
class Perceptron: | |
""" | |
Implementa o Perceptron Learning Algorithm | |
""" | |
w = None |