Python | numpy.fill_diagonal()メソッド

numpy.fill_diagonal() メソッドを使用すると、numpy配列の対角線にパラメーターとして渡された値を numpy.fill_diagonal( )

構文: numpy.fill_diagonal(array、value)
Return:塗りつぶされたものを返します配列の対角線の値。

例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>

#NumPy import

import numpy as np

< br /> #numpy.fill_diagonal()メソッドを使用

配列 = np.zeros(( 3 3 )、 int

np.fill_diagonal(array、 1

print (array)

出力:

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

この記事が問題の解決に役立つことを願っています。 Python | numpy.fill_diagonal()メソッド とは別に、他の Python functions 関連のトピックを確認してください。

Python で上達したいですか?  最高の Python オンライン コース 2023 のレビューをご覧ください。 データ サイエンスに興味がある場合は、R でプログラミングを学ぶ方法も確認してください。

ちなみに、この資料は他の言語でも利用できます:



Ken Danburry

Paris | 2023-03-25

シンプルにまとめられていて分かりやすい。シェアしてくださってありがとうございます。Python | numpy.fill_diagonal()メソッドやPython functionsの問題はいつも私の弱点でした😁。. それが最良の方法であるかどうかはわかりません

Dmitry Danburry

Tallinn | 2023-03-25

Python functionsはちょっと混乱する😭 Python | numpy.fill_diagonal()メソッドは私が遭遇した唯一の問題ではありません。. 卒論で使わせていただきます

Jan Porretti

Texas | 2023-03-25

私はコーディングの面接の準備をしていました、これを明確にしてくれてありがとう - PythonのPython | 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


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