Ejercicio: 2Eva2015TII_T2 funcion totalportipo(tabla)
Solución propuesta en Python, continúa junto al tema 3.
Algoritmo en Python
# ICM00794-Fundamentos de Computación - FCNM-ESPOL
# 2Eva_IIT2015_T2 funcion totalportipo(tabla)
# propuesta de repaso: edelros@espol.edu.ec
import numpy as np
def totalportipo(tabla):
# Tamaño de tabla con codigoplaya,recolectado
n,k = tabla.shape
# verifica banderas repetido cambiando a 1
repetidos = np.zeros(n,dtype=int)
i = 0
while not(i>=(n-1)):
j = i + 1
while not(j>=n):
if (tabla[i,0]==tabla[j,0]):
repetidos[j] = 1
j = j+1
i = i + 1
# cuenta los que se eliminan
# para ver los m que son únicos
eliminar = 0
fila = 0
while not(fila>=n):
eliminar = eliminar + repetidos[fila]
fila = fila + 1
m = n-eliminar
# copiar codigos unicos en tabulado columna 0
tabulado = np.zeros(shape=(m,3), dtype=float)
fila = 0
j = 0
while not(fila>=n):
if (repetidos[fila]==0):
tabulado[j,0] = tabla[fila,0]
j = j + 1
fila = fila + 1
# Cuenta voluntarios por playa en tabulado columna 1
# Acumula recolectado por playa en tabulado columna 2
fila = 0
while not(fila>=n):
cual = tabla[fila,0]
# encuentra el índice en donde
donde = np.where(tabulado[:,0]==cual)
tabulado[donde,1] = tabulado[donde,1] + 1
tabulado[donde,2] = tabulado[donde,2] + tabla[fila,1]
fila = fila + 1
# acumula lo recolectado por playa
return(tabulado)