이 기사에서는 numpy의 기본 데이터 유형, numpy 사용자 정의 복합 데이터 유형, ndarray를 사용하여 날짜 데이터 유형 저장 등을 포함하여 numpy 데이터 유형과 관련된 문제를 주로 정리하는 Python에 대한 관련 지식을 제공합니다. 아래 내용이 모든 분들께 도움이 되기를 바랍니다.
【관련 추천: Python3 동영상 튜토리얼】
1 numpy의 기본 데이터 유형
유형 이름 | 유형 표시기 |
---|---|
Boolean | bool |
부호 있는 정수형 | int8/int16/int32/int64 |
부호 없는 정수형 | uint8/uint16/uint32/uint64 |
부동 소수점형 | float 16/float32/flo at64 |
복수형 type | complex64 / complex128 |
문자 유형 | str, 각 문자는 32비트 유니코드 인코딩 |
import numpy as np arr = np.array([1, 2, 3]) print(arr, arr.dtype) arr = arr.astype('int64') print(arr, arr.dtype) arr = arr.astype('float32') print(arr, arr.dtype) arr = arr.astype('bool') print(arr, arr.dtype) arr = arr.astype('str') print(arr, arr.dtype)
2으로 표시됩니다. 원하다 ndarray에 객체 유형을 저장하기 위해 numpy는 튜플을 사용하여 객체의 속성 필드 값을 저장할 것을 권장하며 ndarray에 튜플을 추가하면 이러한 데이터 처리를 용이하게 하는 구문이 제공됩니다.
import numpy as np data = [ ('zs', [99, 98, 90], 17), ('ls', [95, 95, 92], 16), ('ww', [97, 92, 91], 18) ] # 姓名 2 个字符 # 3 个 int32 类型的成绩 # 1 个 int32 类型的年龄 arr = np.array(data, dtype='2str, 3int32, int32') print(arr) print(arr.dtype) # 可以通过索引访问 print(arr[0], arr[0][2])
데이터의 양이 많은 경우 위의 방법은 데이터 접근에 불편합니다.
ndarray는사전 또는 목록
형식으로 정의할 수 있는 데이터 유형과 열 별칭을 제공합니다. 데이터에 접근할 때 아래 첨자 인덱스나 열 이름을 통해 접근할 수 있습니다.
import numpy as np data = [ ('zs', [99, 98, 90], 17), ('ls', [95, 95, 92], 16), ('ww', [97, 92, 91], 18)]# 采用字典定义列名和元素的数据类型arr = np.array(data, dtype={ # 设置每列的别名 'names': ['name', 'scores', 'age'], # 设置每列数据元素的数据类型 'formats': ['2str', '3int32', 'int32']})print(arr, arr[0]['age'])# 采用列表定义列名和元素的数据类型arr = np.array(data, dtype=[ # 第一列 ('name', 'str', 2), # 第二列 ('scores', 'int32', 3), # 第三列 ('age', 'int32', 1)])print(arr, arr[1]['scores'])# 直接访问数组的一列print(arr['scores'])
3. 날짜 데이터 유형을 저장하려면 ndarray를 사용하세요.
import numpy as np dates = [ '2011', '2011-02', '2011-02-03', '2011-04-01 10:10:10' ] ndates = np.array(dates) print(ndates, ndates.dtype) # 数据类型为日期类型,采用 64 位二进制进行存储,D 表示日期精确到天 ndates = ndates.astype('datetime64[D]') print(ndates, ndates.dtype) # 日期运算 print(ndates[-1] - ndates[0])
3. 시간 쓰기 형식2.
1. 날짜 문자열 지원은
2011/11/11
을 지원하지 않습니다. 분리 날짜는2011 11 11
을 지원하지 않지만,2011-11-11
을 지원합니다를 구분하려면 날짜와 시간 사이에 공백이 있어야 합니다. 2011-04-01 10 :10:10
10:10:10
numpy는 유형을 제공합니다. 데이터 유형을 더욱 편리하게 처리할 수 있는 문자 코드입니다.
2011/11/11
,使用空格进行分隔日期也不支持2011 11 11
,支持2011-11-11
2.日期与时间之间需要有空格进行分隔2011-04-01 10:10:10
3.时间的书写格式10:10:10
4. 유형 문자 코드(데이터 유형 약어)
문자 코드 | ||
---|---|---|
? | 부호 있는 정수 유형 | |
i1/i2/ i4/i8 | 부호 없는 정수 | |
u1/u2/u4/u8 | 부동 소수점 | |
f2 4 / f8 | complex64 / complex128 | |
문자 유형 | str, 각 문자는 32비트 유니코드 인코딩 | |
Date | datatime64 | |
5. 필드를 선택하고 ndarray Store 데이터를 사용합니다.
import numpy as np datas = [ (0, '4室1厅', 298.79, 2598, 86951), (1, '3室2厅', 154.62, 1000, 64675), (2, '3室2厅', 177.36, 1200, 67659),]arr = np.array(datas, dtype={ 'names': ['index', 'housetype', 'square', 'totalPrice', 'unitPrice'], 'formats': ['u1', '4U', 'f4', 'i4', 'i4']})print(arr)print(arr.dtype)# 计算 totalPrice 的均值sum_totalPrice = sum(arr['totalPrice'])print(sum_totalPrice/3)
【관련 권장 사항:
Python3 비디오 튜토리얼】
위 내용은 Python 데이터 유형 소개 - numpy의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

PythonArraysSupportVariousOperations : 1) SlicingExtractsSubsets, 2) 추가/확장 어드먼트, 3) 삽입 값 삽입 ATSpecificPositions, 4) retingdeletesElements, 5) 분류/ReversingChangesOrder 및 6) ListsompectionScreateNewListSbasedOnsistin

NumpyArraysareSentialplosplicationSefficationSefficientNumericalcomputationsanddatamanipulation. Theyarcrucialindatascience, MachineLearning, Physics, Engineering 및 Financeduetotheiribility에 대한 handlarge-scaledataefficivally. forexample, Infinancialanyaly

UseanArray.ArrayOveralistInpyThonWhendealingwithhomogeneousData, Performance-CriticalCode, OrinterFacingwithCcode.1) HomogeneousData : ArraysSaveMemorywithtypepletement.2) Performance-CriticalCode : arraysofferbetterporcomanceFornumericalOperations.3) Interf

아니요, NOTALLLISTOPERATIONARESUPPORTEDBYARRARES, andVICEVERSA.1) ArraySDONOTSUPPORTDYNAMICOPERATIONSLIKEPENDORINSERTWITHUTRESIGING, WHITHIMPACTSPERFORMANCE.2) ListSDONOTEECONSTANTTIMECOMPLEXITEFORDITITICCESSLIKEARRAYSDO.

ToaccesselementsInapyThonlist, 사용 인덱싱, 부정적인 인덱싱, 슬라이스, 오리 화.

Arraysinpython, 특히 비밀 복구를위한 ArecrucialInscientificcomputing.1) theaRearedFornumericalOperations, DataAnalysis 및 MachinELearning.2) Numpy'SimplementationIncensuressuressurations thanpythonlists.3) arraysenablequick

Pyenv, Venv 및 Anaconda를 사용하여 다양한 Python 버전을 관리 할 수 있습니다. 1) PYENV를 사용하여 여러 Python 버전을 관리합니다. Pyenv를 설치하고 글로벌 및 로컬 버전을 설정하십시오. 2) VENV를 사용하여 프로젝트 종속성을 분리하기 위해 가상 환경을 만듭니다. 3) Anaconda를 사용하여 데이터 과학 프로젝트에서 Python 버전을 관리하십시오. 4) 시스템 수준의 작업을 위해 시스템 파이썬을 유지하십시오. 이러한 도구와 전략을 통해 다양한 버전의 Python을 효과적으로 관리하여 프로젝트의 원활한 실행을 보장 할 수 있습니다.

Numpyarrayshaveseveraladvantagesstandardpythonarrays : 1) thearemuchfasterduetoc 기반 간증, 2) thearemorememory-refficient, 특히 withlargedatasets 및 3) wepferoptizedformationsformationstaticaloperations, 만들기, 만들기


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

Eclipse용 SAP NetWeaver 서버 어댑터
Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.

ZendStudio 13.5.1 맥
강력한 PHP 통합 개발 환경

맨티스BT
Mantis는 제품 결함 추적을 돕기 위해 설계된 배포하기 쉬운 웹 기반 결함 추적 도구입니다. PHP, MySQL 및 웹 서버가 필요합니다. 데모 및 호스팅 서비스를 확인해 보세요.

PhpStorm 맥 버전
최신(2018.2.1) 전문 PHP 통합 개발 도구
