Skip to content

Instantly share code, notes, and snippets.

@antonioFlavio
Created February 28, 2019 01:11
Show Gist options
  • Save antonioFlavio/1ea2ada41dddf086867259f2cbe3bfd5 to your computer and use it in GitHub Desktop.
Save antonioFlavio/1ea2ada41dddf086867259f2cbe3bfd5 to your computer and use it in GitHub Desktop.
import numpy as np
O = str(input())
tamanho_da_matriz = 12
# Cria uma matriz de zeros
matriz = np.zeros((tamanho_da_matriz, tamanho_da_matriz))
# Preenche a matriz
for linha in range(tamanho_da_matriz):
for coluna in range(tamanho_da_matriz):
matriz[linha][coluna] = np.random.random() # float(input())
coluna_inicio = int(tamanho_da_matriz/2) - 1
coluna_fim = int(tamanho_da_matriz/2)
linha_inicio = int(tamanho_da_matriz/2) + 1
valores = []
# Percorre a parte inferior da matriz, adicionando os valores a um array.
for linha in range(linha_inicio, tamanho_da_matriz):
for coluna in range(coluna_inicio, coluna_fim):
valores.append(matriz[linha, coluna])
coluna_inicio -= 1
coluna_fim += 1
valores_np = np.array(valores)
if O == "S":
print(np.sum(valores_np))
else:
print(np.average(valores_np))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment