소개
과학적인 계산이나 시뮬레이션을 할 때 많은 친구들이 이런 문제에 직면할 것이라고 생각합니다. 예를 들어 아래와 같은 1차원 배열이 있습니다.
array = [1, 2, 3, 4, 5]
이때 우리는 이를 스택을 따라 반복적으로 이동하려고 합니다. 예를 들어 여기서는 y축을 3번 설정하여 다음 배열을 얻을 수 있습니다.
[[1. 2. 3. 4. 5.] [1. 2. 3. 4. 5.] [1. 2. 3. 4. 5.]]
그럼 우리는 어떻게 해야 할까요?
일반적인 방법
import numpy as np array = np.array([1, 2, 3, 4, 5]) # 原始数组 repeat_time = 3 # 沿着y轴堆叠的次数 array_final = np.ones([repeat_time, len(array)]) for i in range(repeat_time): array_final[i, :] = array print(array_final) """ result: [[1. 2. 3. 4. 5.] [1. 2. 3. 4. 5.] [1. 2. 3. 4. 5.]] """
np.repeat 함수 사용
분명히 위의 방법이 더 번거롭습니다. 단순화하기 위해 np.repeat() 함수를 사용하여 이 기능을 구현할 수 있습니다.
import numpy as np array = np.array([1, 2, 3, 4, 5]) # 原始数组 repeat_time = 3 # 沿着y轴堆叠的次数 array_final = np.repeat(array.reshape(1, -1), axis=0, repeats=repeat_time) print(array_final) """ result: [[1 2 3 4 5] [1 2 3 4 5] [1 2 3 4 5]] """
np.repeat() 함수의 자세한 사용법은 이 글을 참고해주세요------np.repeat() 함수.
np.meshgrid 함수를 사용하세요
물론, 이런 상황에서는 가장 쉬운 방법은 np.meshgrid() 함수를 사용하여 처리하는 것입니다.
import numpy as np array = np.array([1, 2, 3, 4, 5]) # 原始数组 repeat_time = 3 # 沿着y轴堆叠的次数 array_1 = array.copy()[0:repeat_time] array_final, array_final1 = np.meshgrid(array, array_1) print(array_final) """ result: [[1 2 3 4 5] [1 2 3 4 5] [1 2 3 4 5]] """
물론 이 작업을 수행할 수 있는 np.vstack() 및 np.concatenate() 함수와 같은 다른 방법이 있습니다. 이 두 함수에 대해서는 블로그------np.concatenate() 함수와 np.vstack() 함수를 볼 수 있습니다.
위 내용은 Python에서 여러 행의 반복 데이터를 생성하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

PythonlistsCanstoreAnyDatAtype, ArrayModuLearRaysStoreOneType 및 NUMPYARRAYSAREFORNUMERICALPUTATION.1) LISTSAREVERSATILEBUTLESSMEMORY-EFFICENT.2) ARRAYMODUERRAYRAYRAYSARRYSARESARESARESARESARESARESAREDOREDORY-UNFICEDONOUNEOUSDATA.3) NumpyArraysUraysOrcepperperperperperperperperperperperperperperperferperferperferferpercient

whenyouattempttoreavalueofthewrongdatatypeinapythonaphonarray, thisiSdueTotheArrayModule의 stricttyPeenforcement, theAllElementStobeofthesAmetypecified bythetypecode.forperformancersassion, arraysaremoreficats the thraysaremoreficats thetheperfication the thraysaremorefications는

Pythonlistsarepartoftsandardlardlibrary, whileraysarenot.listsarebuilt-in, 다재다능하고, 수집 할 수있는 반면, arraysarreprovidedByTearRaymoduledlesscommonlyusedDuetolimitedFunctionality.

thescriptIsrunningwithHongpyThonversionDueCorRectDefaultTerpretersEttings.tofixThis : 1) checktheDefaultPyThonVersionUsingPyThon-VersionorPyThon3- version.2) usvirtual-ErondmentsBythePython.9-Mvenvmyenv, 활성화, 및 파괴

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.


핫 AI 도구

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

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

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

Clothoff.io
AI 옷 제거제

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

인기 기사

뜨거운 도구

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

Atom Editor Mac 버전 다운로드
가장 인기 있는 오픈 소스 편집기

드림위버 CS6
시각적 웹 개발 도구

WebStorm Mac 버전
유용한 JavaScript 개발 도구

DVWA
DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는
