打 Kar覺覺k Notlar

Matrix 襤lemleri

A, B, C gibi semboller matrix belirtir.

1e-7 == 0.0000001 # True (10 ^ -7)
1e+4 == 1000 # True (10^4)
A = (A < 5) # 5'ten k羹癟羹k ise true
np.mean(A) # Ortalama A'n覺n deeri (true ya da false)
A = A[A > 5] # 5 ten b羹y羹k olanlar覺 alma
# Maskeleme (5'ten k羹癟羹k olanlar s覺f覺rlan覺r)
A = np.multiply(A, A < 5)

Jupyter Notlar覺

  • ALT'a bas覺l覺 tutarak s羹tun se癟imi yapabilirsin

  • ALT GR'e bas覺l覺 tutarak birden fazla imle癟 ekleyebilirsin

  • SHIFT'e bas覺l覺 tutarak y繹n tular覺 ile metin se癟imi yapabilrisin

Temel zellikleri

  • Matematiksel (vekt繹r tabanl覺) ilemler i癟in ka癟覺n覺lmazd覺r

  • Python i癟in SIML (single instruction multiple ...) yap覺s覺n覺 kullan覺r

  • Single thread deil multi thread 癟al覺覺r. (multiprogramming)

  • Optimize edilmitir ve for d繹ng羹lerinden 300 kata kadar daha h覺zl覺d覺r

Temel Fonksiyonlar

import numpy as np
np.sum(<V>, <V>) # Vekt繹rel toplama
np.dot(<V>, <V>) # Vekt繹rel 癟arpma
np.exp(<V>, <V>) # Vekt繹rel e^
np.log(<V>, <V>) # Vekt繹rel log
np.max(<V>, <V>) # Vekt繹rel en y羹ksek deeri bulma
np.min(<V>, <V>) # Vekt繹rel min deeri bulma
np.mean(<V>) # Vekt繹rel ortalama alma
np.where(<koul>, <true>, <false>) # Vekt繹rel If-else

IF-Else Yap覺s覺

One IF-ELIF

Approach #1 One approach:

keep_mask = X==50
out = np.where(X>50,0,1)
out[keep_mask] = 50

Approach #2 Alternatively, for in-situ edit:

replace_mask = X!=50
X[replace_mask] = np.where(X>50,0,1)[replace_mask]
# Or (X<=50).astype(int) in place of np.where(X>50,0,1)

Code-golf? If you actually want to play code-golf/one-liner:

(X<=50)+(X==50)*49

Multiple IF-ELIFs

Approach #1:

For a bit more generic case involving more if-elif parts, we could make use of np.searchsorted -

out_X = np.where(X<=40,0, np.searchsorted([40,50,60,70,80,90], X)+3)

Kaynak

Harici Kaynaklar