蟒蛇 | numpy.fill_diagonal () 方法

使用 numpy.fill_diagonal() 方法,您可以使用作為參數傳遞給 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]]

示例#2:

< /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]]

我們希望本文能幫助您解決問題。 除了 蟒蛇 | numpy.fill_diagonal () 方法,查看其他與 Python functions 相關的主題。

想在 Python 中出類拔萃? 查看我們對 最佳 Python 在線課程 2023的評論。 如果您對數據科學感興趣,請查看如何學習 R 編程

順便說一句,此材料也有其他語言版本:



Anna Porretti

Moscow | 2023-03-25

简单地说,很清楚。谢谢你的分享。蟒蛇 | numpy.fill_diagonal () 方法和其他问题的Python functions一直是我的弱点😁。. 將在我的學士論文中使用它

Ken Krasiko

Moscow | 2023-03-25

我正在为我的编码面试做准备,谢谢你的澄清--Python中的蟒蛇 | numpy.fill_diagonal () 方法并不是最简单的一个。. 明天會回來反饋

Xu Danburry

Texas | 2023-03-25

也许有其他的答案?什么是蟒蛇 | numpy.fill_diagonal () 方法?到底是什么意思?. 昨天檢查了,有效!

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