Python | numpy.fill_diagonal() yöntemi

numpy.fill_diagonal() yöntemini kullanarak, bir numpy dizisinin köşegenlerini numpy.fill_diagonal öğesine parametre olarak iletilen değerle doldurabilirsiniz ( ) .

Sözdizimi: numpy.fill_diagonal (dizi, değer)
Döndür: Doldurulanı döndürür bir dizinin köşegenindeki değer.

Örnek 1:
Bu örnekte, numpy.fill_diagonal ( ) kullanarak elde edebileceğimizi görebiliriz. parametre olarak geçirilen değerlerle dolu köşegenler.

# NumPy içe aktarma

içe aktarma np olarak numpy


# numpy.fill_diagonal() yöntemini kullanarak

dizi = np.array ([[ 1 , 2 ], [ 2 , 1 ]])

< kod sınıfı = "düz"> np .fill_diagonal (dizi, 5 )

yazdır (dizi)

Çıktı:

[[5 2]
[2 5]]

Örnek # 2:

< /p>

# NumPy içe aktarma

içe aktarma np olarak numpy

< br /> # numpy.fill_diagonal() yöntemini kullanarak

dizi = np.zeros (( 3 , 3 ), int )

np.fill_diagonal (dizi, 1 )

yazdır (dizi)

Çıktı:

[ [1 0 0]
[0 1 0]
[0 0 1]]

Bu makalenin sorunu çözmenize yardımcı olduğunu umuyoruz. Python | numpy.fill_diagonal() yöntemi dışında, Python functions ile ilgili diğer konulara bakın.

Python'da başarılı olmak ister misiniz? en iyi Python çevrimiçi kursları 2023 hakkındaki incelememize bakın. Veri Bilimi ile ilgileniyorsanız, R'de programlamayı nasıl öğreneceğinizi de kontrol edin.

Bu arada, bu materyal diğer dillerde de mevcuttur:



Walter Robinson

Moscow | 2023-03-25

Basitçe ifade edilmiş ve açık. Paylaşım için teşekkürler. Python | numpy.fill_diagonal() yöntemi ve Python functions ile ilgili diğer konular her zaman benim zayıf noktam olmuştur 😁. Geri bildirim ile yarın geri dönecek

Chen Robinson

Paris | 2023-03-25

Python functions her şey biraz kafa karıştırıcı 😭 Python | numpy.fill_diagonal() yöntemi karşılaştığım tek sorun değil. Umarım artık ortaya çıkmaz

Xu Chamberlet

Paris | 2023-03-25

Python functions her şey biraz kafa karıştırıcı 😭 Python | numpy.fill_diagonal() yöntemi karşılaştığım tek sorun değil. Lisans tezimde kullanacağım

Shop

Gifts for programmers

Learn programming in R: courses

$FREE
Gifts for programmers

Best Python online courses for 2022

$FREE
Gifts for programmers

Best laptop for Fortnite

$399+
Gifts for programmers

Best laptop for Excel

$
Gifts for programmers

Best laptop for Solidworks

$399+
Gifts for programmers

Best laptop for Roblox

$399+
Gifts for programmers

Best computer for crypto mining

$499+
Gifts for programmers

Best laptop for Sims 4

$

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

1947 answers

PythonStackOverflow

Check if one list is a subset of another in Python

1173 answers

PythonStackOverflow

How to specify multiple return types using type-hints

1002 answers

PythonStackOverflow

Printing words vertically in Python

909 answers

PythonStackOverflow

Python Extract words from a given string

798 answers

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

606 answers

PythonStackOverflow

Python os.path.join () method

384 answers

PythonStackOverflow

Flake8: Ignore specific warning for entire file

360 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically