Pythonschlange | numpy.fill_diagonal ()-Methode

Mit der Methode numpy.fill_diagonal() können Sie die Diagonalen eines numpy-Arrays mit dem Wert füllen, der als Parameter an numpy.fill_diagonal ( ) .

Syntax: numpy.fill_diagonal (array, value)
Return: Gibt das Gefüllte zurück Wert in der Diagonale eines Arrays.

Beispiel Nr. 1:
In diesem Beispiel können wir sehen, dass wir mit numpy.fill_diagonal ( ) erhalten können die Diagonalen gefüllt mit den als Parameter übergebenen Werten.

# NumPy import

import numpy as np


# unter Verwendung der Methode numpy.fill_diagonal ()

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

np .fill_diagonal (array, 5 )

print (array)

Ausgabe:

[[5 2]
[2 5]]

Beispiel Nr. 2:

< /p>

Ausgabe:

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

Wir hoffen, dass dieser Artikel Ihnen geholfen hat, das Problem zu lösen. Sehen Sie sich neben Pythonschlange | numpy.fill_diagonal ()-Methode auch andere Python functions-bezogene Themen an.

Möchten Sie sich in Python auszeichnen? Sehen Sie sich unseren Rückblick auf die besten Python-Online-Kurse 2023 an. Wenn Sie an Data Science interessiert sind, sehen Sie sich auch an, wie Sie Programmieren in R lernen.

Dieses Material ist übrigens auch in anderen Sprachen verfügbar:



Schneider Zelotti

New York | 2023-03-25

Vielleicht gibt es andere Antworten? Was bedeutet Pythonschlange | numpy.fill_diagonal ()-Methode genau bedeutet?. Melde mich morgen mit Rückmeldung

Xu Robinson

Milan | 2023-03-25

Einfach und klar formuliert. Danke für den Austausch. Pythonschlange | numpy.fill_diagonal ()-Methode und andere Fragen mit Python functions war immer mein Schwachpunkt 😁. Melde mich morgen mit Rückmeldung

Anna Robinson

California | 2023-03-25

Danke für die Erklärungen! Ich steckte mit Pythonschlange | numpy.fill_diagonal ()-Methode für einige Stunden, endlich habe ich es geschafft 🤗. Ich bin mir nur nicht ganz sicher, ob es die beste Methode ist

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


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

# NumPy import

import numpy as np

< br /> # unter Verwendung der Methode numpy.fill_diagonal ()

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

np.fill_diagonal (array, 1 )

print (array)