파이썬 | numpy.fill_diagonal() 메서드

numpy.fill_diagonal() 메서드를 사용하여 numpy.fill_diagonal( ) .

구문: numpy.fill_diagonal (배열, 값)
반환: 채워진 값 반환 배열의 대각선에 있는 값.

예 # 1:
이 예에서 numpy.fill_diagonal ( ) 를 사용하여 다음을 얻을 수 있음을 알 수 있습니다. 매개변수로 전달된 값으로 채워진 대각선.

<표 테두리 = "0" cellpadding = "0" cellspacing = "0">

# NumPy 가져오기

가져오기 numpy를 np로


# numpy.fill_diagonal() 메서드 사용

배열

코드> <코드 클래스 = "키워드 "> = <코드 클래스 ="일반 "> np.array ([[
<코드 클래스 ="값 "> 1 <코드 클래스 ="일반 ">, <코드 클래스 = "값"> 2 <코드 클래스 = "일반">], [ <코드 클래스 = "값"> 2 <코드 클래스 = "일반" >, <코드 클래스 = "값"> 1 <코드 클래스 = "일반">]])

< 코드 클래스 = "일반"> np .fill_diagonal (배열, <코드 클래스 = "값"> 5 <코드 클래스 = "일반">)

인쇄 (배열)

출력:

[[5 2]
[2 5]]

예제 # 2:

< /p>

<표 테두리 = "0" cellpadding = "0" cellspacing = "0">

# NumPy 가져오기

가져오기 numpy를 np로

< br /> # numpy.fill_diagonal() 메서드 사용

배열 = <코드 클래스 = "일반 "> np.zeros (( <코드 클래스 ="값 "> 3 <코드 클래스 ="일반 ">, <코드 클래스 ="값 "> 3 <코드 클래스 = "일반">), <코드 클래스 = "함수"> int <코드 클래스 = "일반">)

np.fill_diagonal (배열, 1 )

<코드 클래스 = "함수"> 인쇄 <코드 클래스 = "일반"> (배열)

출력:

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

이 문서가 문제를 해결하는 데 도움이 되었기를 바랍니다. 파이썬 | numpy.fill_diagonal() 메서드 외에 다른 Python functions 관련 주제를 확인하세요.

파이썬에서 뛰어나고 싶으십니까? 2023최고의 Python 온라인 과정에 대한 검토를 참조하세요. 데이터 과학에 관심이 있다면 R로 프로그래밍을 배우는 방법도 확인하세요.

그런데 이 자료는 다른 언어로도 제공됩니다.



Chen Innsbruck

London | 2023-03-25

Python functions은(는) 모든 것이 약간 혼란스럽습니다 😭 파이썬 | numpy.fill_diagonal() 메서드이(가) 만난 유일한 문제는 아닙니다.. 더 이상 나타나지 않기를 바랄뿐입니다

Cornwall Lehnman

Paris | 2023-03-25

다른 답이 있지 않을까요? 뭐 파이썬 | numpy.fill_diagonal() 메서드 은(는) 정확히 무엇을 의미합니까?. 내 학사 논문에 사용할 것입니다

Anna Danburry

Rome | 2023-03-25

코딩 인터뷰를 준비하고 있었습니다. 명확히 해 주셔서 감사합니다. 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

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