파이썬[Python]: numpy - asanyarray 함수

numpy 모듈 - asanyarray 함수(function)


/// 설명

입력을 배열(ndarray)로 변환합니다.(ndarray subclass를 허용합니다.)

a: 입력 데이터 입니다.(입력: 리스트, 튜플, ndarray)
dtype: 출력할 배열의 데이터 형식입니다. 기본값으로 입력 데이터 형식을 따릅니다.
order: 결과물의 메모리 저장 형식을 결정합니다. 'C'는 C언어 형식, 'F'는 포트란 형식입니다. 'A'는 prototype이 포트란 연속(Fortran contiguous)이면 'F', 아니면 'C'로 결정됩니다. 'K'(keep)는 입력 a 의 형식을 보존합니다. 기본값은 'K' 입니다.
like: Numpy 배열이 아닌 형태로 생성하는 것을 허용합니다.(__array_function__ 프로토콜을 사용합니다.)

※ 형식
numpy.asanyarray(a, dtype=None, order=None, *, like=None)

reference
https://numpy.org/devdocs/reference/generated/numpy.asanyarray.html

/// 예제 array-like

1
2
3
4
5
6
7
8
9
10
11
12
import numpy as np
 
test = np.array([(1.02), (3.04)], dtype='f4,i4')
print(test)  # [(1., 2) (3., 4)]
print(np.asarray(test) is test)  # True
print(np.asanyarray(test) is test)  # True
 
test = np.array([(1.02), (3.04)], dtype='f4,i4').view(np.recarray)
print(test)  # [(1., 2) (3., 4)]
print(np.asarray(test) is test)  # False
print(np.asanyarray(test) is test)  # True
 
cs

* 실행환경: Microsoft Windows 10 Homes
* 인터프리터: 파이썬(Python 3.9)


– 당신을 응원합니다. –

댓글

이 블로그의 인기 게시물

파이썬[Python]: 내장함수 - from_bytes 메서드

파이썬[Python]: 내장함수 - __len__ 메서드

파이썬[Python]: kivy - 한글 사용

파이썬[Python]: 내장함수 - bit_length 메서드

C 언어: sin 함수, cos 함수, tan 함수