BaşlayınÜcretsiz Başlayın

Hepsini bir araya getirelim: Pokémon z-skorları

720 Pokémon'dan oluşan bir liste oturumuna names olarak yüklendi. Her Pokémon'un Health Points (Can Puanı) değeri hps adlı bir NumPy dizisinde saklı. Her Pokémon'un HP'sinin tüm HP'lerin ortalamasından kaç standart sapma uzakta olduğunu görmek için z-skoru ile HP'leri analiz etmek istiyorsun.

Aşağıdaki kod, her Pokémon için HP z-skorunu hesaplamak ve z-skorlarına göre en yüksek HP'ye sahip Pokémon'ları toplamak için yazıldı:

poke_zscores = []

for name,hp in zip(names, hps):
    hp_avg = hps.mean()
    hp_std = hps.std()
    z_score = (hp - hp_avg)/hp_std
    poke_zscores.append((name, hp, z_score))
highest_hp_pokemon = []

for name,hp,zscore in poke_zscores:
    if zscore > 2:
        highest_hp_pokemon.append((name, hp, zscore))

Bu egzersiz

Verimli Python Kodu Yazmak

kursunun bir parçasıdır
Kursu Görüntüle

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Calculate the total HP avg and total HP standard deviation
hp_avg = ____.____
hp_std = ____.____

# Use NumPy to eliminate the previous for loop
z_scores = (____ - ____)/____

# Combine names, hps, and z_scores
poke_zscores2 = [*____(names, hps, z_scores)]
print(*poke_zscores2[:3], sep='\n')
Kodu Düzenle ve Çalıştır