Ich möchte $ _4C_2 $ in Python finden. Mit scipy.special.comb, einer Bibliothek namens scipy, scheint dies einfach zu sein.
Wenn Sie wie folgt schreiben
import scipy
print(scipy.special.comb(4, 2))
Error
AttributeError: module 'scipy' has no attribute 'special'
Es ist in Ordnung, wie folgt zu schreiben
from scipy.special import comb
print(comb(4, 2))
Ausführungsergebnis
6.0
Folgendes ist ebenfalls möglich
from scipy import special
print(special.comb(4, 2))
import scipy
nicht
from scipy.special import comb
or
from scipy import special
Recommended Posts