파이썬의 numpy.asanyarray()

Python functions

numpy.asanyarray() 는 입력을 배열로 변환하고 싶지만 ndarray의 하위 클래스를 건너뛸 때 사용됩니다. 입력 데이터는 스칼라, 목록, 튜플 목록, 튜플, 튜플 튜플, 목록 튜플 및 ndarray일 수 있습니다.

구문: numpy.asanyarray(arr, dtype = None, order = None)

매개변수:
arr: [array_like] 다음으로 변환할 수 있는 모든 형식의 입력 데이터 배열. 여기에는 스칼라, 목록, 튜플 목록, 튜플, 튜플 튜플, 목록 튜플 및 ndarray가 포함됩니다.
dtype: [data-type, optional] 기본적으로 데이터 유형은 입력 데이터에서 추론됩니다.
순서: 행 우선(C 스타일) 또는 열 우선(포트란 스타일) 메모리 표현을 사용할지 여부입니다. 기본값은 `C`입니다.

반환: [ndarray 또는 ndarray 하위 클래스] arr의 배열 해석입니다. arr이 ndarray이거나 ndarray의 하위 클래스이면 있는 그대로 반환되고 복사가 수행되지 않습니다.

코드 # 1: 배열에서 배열로

# Python 프로그램 설명
# numpy .asanyarray () 함수


가져오기 괴짜로 numpy

<코드 클래스 ="일반 "> my_list <코드 클래스 ="키워드 "> = <코드 클래스 ="일반 "> [ <코드 클래스 = "값" > 1 <코드 클래스 = "일반">, <코드 클래스 = "값"> 3 <코드 클래스="일반">, <코드 클래스 =" 값 "> 5 <코드 클래스 ="일반 ">, <코드 클래스 ="값 "> 7 <코드 클래스 = "일반">, <코드 클래스 = "값"> 9 <코드 클래스 = "일반">]

<코드 클래스 = "정의되지 않은 공백" >

인쇄 ( "입력 목록:" , my_list)



out_arr <코드 클래스 ="키워드 "> = <코드 클래스 ="일반 "> geek.asanyarray (my_list)

인쇄 ( " 입력 목록의 출력 배열: " , out_arr)

출력:

입력 목록: [1, 3, 5, 7, 9] 입력 목록의 출력 배열 : [1 3 5 7 9] 

코드 # 2: 튜플을 배열로

# 파이썬 프로그램 설명
# numpy.asanyarray() 함수


가져오기 괴짜로 numpy

my_tuple < 코드 클래스 = "키워드"> = <코드 클래스 = "일반"> ([ <코드 클래스 = "값 "> 1 <코드 클래스 ="일반 ">, <코드 클래스 ="값 "> 3 <코드 클래스 ="일반 ">, <코드 클래스 = "값"> 9 <코드 클래스 = "일반">] , [ <코드 클래스 = "값"> 8 <코드 클래스 = "일반">, <코드 클래스 = "값"> 2 <코드 클래스 = " 일반">, <코드 클래스 = "값"> 6 <코드 클래스 = "일반">])


<코드 클래스 = " functions"> 인쇄 ( "입력 튜플:" , my_tuple)

out_arr = 괴짜 .asanyarray (my_tuple)

인쇄 ( "입력 튜플의 출력 배열:" , out_arr)

출력:

입력 튜플: ( [1, 3, 9], [8, 2, 6]) 출력 배열 입력 튜플: [[1 3 9] [8 2 6]] 

코드 # 3: 스칼라 k 배열


<테이블 테두리 = "0 " cellpadding = "0" cellspacing = "0">

# 파이썬 프로그램 설명
# numpy.asanyarray () 함수


가져오기 numpy as 괴짜

my_scalar <코드 클래스 = " 키워드"> = <코드 클래스 = "값"> 12


<코드 클래스 = "함수"> 인쇄 <코드 클래스 = "일반 "> ( " 입력 스칼라: " , my_scalar)

out_arr = geek.asanyarray (my_scalar)

인쇄 ( "입력 스칼라의 출력 배열:" , out_arr)

인쇄 ( 유형 (out_arr))

출력:

입력 스칼라: 12 입력 스칼라의 출력 배열: 12 class `numpy.ndarray ` 

Shop

Gifts for programmers

Best Python online courses for 2022

$FREE
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

$
Gifts for programmers

Best laptop for Zoom

$499
Gifts for programmers

Best laptop for Minecraft

$590

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