蟒蛇 | numpy.fill_diagonal () 方法

` 語法： numpy.fill_diagonal(array, value) 返回： 返回填充的數組對角線上的值。 `
` Example #1: 在這個例子中，我們可以看到使用 numpy.fill_diagonal ( ) 我們可以得到用作為參數傳遞的值填充的對角線。 # NumPy import import numpy as np #使用numpy.fill_diagonal()方法 數組 = np.array ([[ 1 , 2 ], [ 2 , 1 ]]) np .fill_diagonal (array, 5 ) print (array) `

` `

[[5 2]
[2 5]]

< /p>

<表格邊框 = "0" cellpadding = "0" cellspacing = "0">

` # NumPy import `

` import ` ` numpy as np `

< br /> ` # 使用 numpy.fill_diagonal() 方法 `

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

` np.fill_diagonal (array, ` ` 1 ` `) `

` print ` ` (數組) `

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

Anna Porretti

Moscow | 2023-03-25

Ken Krasiko

Moscow | 2023-03-25

Xu Danburry

Texas | 2023-03-25

Shop

Learn programming in R: courses

\$FREE

Best Python online courses for 2022

\$FREE

Best laptop for Fortnite

\$399+

Best laptop for Excel

\$

Best laptop for Solidworks

\$399+

Best laptop for Roblox

\$399+

Best computer for crypto mining

\$499+

Best laptop for Sims 4

\$

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

PythonStackOverflow

Check if one list is a subset of another in Python

PythonStackOverflow

How to specify multiple return types using type-hints

PythonStackOverflow

Printing words vertically in Python

PythonStackOverflow

Python Extract words from a given string

PythonStackOverflow

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

PythonStackOverflow

Python os.path.join () method

PythonStackOverflow

Flake8: Ignore specific warning for entire file

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