{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 数据拼接\n", "\n", "1. np.concatenate 是numpy中对array进行拼接的函数\n", "axis参数为指定按照哪个维度进行拼接" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[[ 2.62434536 0.38824359 0.47182825 -0.07296862]\n", " [ 1.86540763 -1.3015387 2.74481176 0.2387931 ]\n", " [ 1.3190391 0.75062962 2.46210794 -1.06014071]\n", " [ 0.6775828 0.61594565 2.13376944 -0.09989127]\n", " [ 0.82757179 0.12214158 1.04221375 1.58281521]] \n", " (5, 4) \n", "\n", "[[-0.10061918 2.14472371 1.90159072 1.50249434]\n", " [ 1.90085595 0.31627214 0.87710977 0.06423057]\n", " [ 0.73211192 1.53035547 0.30833925 0.60324647]] \n", " (3, 4) \n", "\n", "[[ 0.3128273 0.15479436]\n", " [ 0.32875387 0.9873354 ]\n", " [-0.11731035 1.2344157 ]\n", " [ 2.65980218 1.74204416]\n", " [ 0.80816445 0.11237104]] \n", " (5, 2) \n", "\n", "[[ 2.62434536 0.38824359 0.47182825 -0.07296862]\n", " [ 1.86540763 -1.3015387 2.74481176 0.2387931 ]\n", " [ 1.3190391 0.75062962 2.46210794 -1.06014071]\n", " [ 0.6775828 0.61594565 2.13376944 -0.09989127]\n", " [ 0.82757179 0.12214158 1.04221375 1.58281521]\n", " [-0.10061918 2.14472371 1.90159072 1.50249434]\n", " [ 1.90085595 0.31627214 0.87710977 0.06423057]\n", " [ 0.73211192 1.53035547 0.30833925 0.60324647]] \n", " (8, 4) \n", "\n", "[[ 2.62434536 0.38824359 0.47182825 -0.07296862 0.3128273 0.15479436]\n", " [ 1.86540763 -1.3015387 2.74481176 0.2387931 0.32875387 0.9873354 ]\n", " [ 1.3190391 0.75062962 2.46210794 -1.06014071 -0.11731035 1.2344157 ]\n", " [ 0.6775828 0.61594565 2.13376944 -0.09989127 2.65980218 1.74204416]\n", " [ 0.82757179 0.12214158 1.04221375 1.58281521 0.80816445 0.11237104]] \n", " (5, 6) \n", "\n" ] } ], "source": [ "rdm = np.random.RandomState(1)\n", "x1 = rdm.normal(1,1,(5,4))\n", "x2 = rdm.normal(1,1,(3,4))\n", "x3 = rdm.normal(1,1,(5,2))\n", "print(x1,\"\\n\",x1.shape,\"\\n\")\n", "print(x2,\"\\n\",x2.shape,\"\\n\")\n", "print(x3,\"\\n\",x3.shape,\"\\n\")\n", "\n", "con1 = np.concatenate([x1,x2],axis=0)\n", "print(con1,\"\\n\",con1.shape,\"\\n\")\n", "\n", "con2 = np.concatenate([x1,x3],axis=1)\n", "print(con2,\"\\n\",con2.shape,\"\\n\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.13 ('gym')", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.13" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "eb62451c918ef6a4174992a3510c06ea27ba0bc2fc5ee7a9f470b6f52b0b170f" } } }, "nbformat": 4, "nbformat_minor": 2 }