add cut and split
This commit is contained in:
@@ -3,3 +3,4 @@ This repo is a note of numpy leaning
|
||||
## Content
|
||||
|
||||
[random](./random.ipynb)
|
||||
[cut and split](./cut_split.ipynb)
|
||||
|
||||
121
cut_split.ipynb
Normal file
121
cut_split.ipynb
Normal file
@@ -0,0 +1,121 @@
|
||||
{
|
||||
"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
|
||||
}
|
||||
40
random.ipynb
40
random.ipynb
@@ -134,12 +134,22 @@
|
||||
"功能: 生成[0,1)之间的浮点数,通过size参数来指定维数。\n",
|
||||
"说明:\n",
|
||||
"size : int or tuple of ints, optional.\n",
|
||||
"Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. Default is None, in which case a single value is returned. "
|
||||
"Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. Default is None, in which case a single value is returned. \n",
|
||||
"\n",
|
||||
"4. numpy.random.rand()\n",
|
||||
"均匀分布\n",
|
||||
"范围 [0, 1)\n",
|
||||
"\n",
|
||||
"5. numpy.random.normal(loc=mu, scale=sigma, size)\n",
|
||||
"正态分布\n",
|
||||
"mu,均值\n",
|
||||
"sigma,标准差\n",
|
||||
"size,数据shape,默认一个值"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 21,
|
||||
"execution_count": 25,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -148,17 +158,21 @@
|
||||
"text": [
|
||||
"[0 0 0 0] \n",
|
||||
"\n",
|
||||
"[[ 0 -2 0]\n",
|
||||
" [ 1 -1 -1]] \n",
|
||||
"[[ 2 1 0]\n",
|
||||
" [-2 0 0]] \n",
|
||||
"\n",
|
||||
"0.0940234518052504 \n",
|
||||
"0.9888926077885405 \n",
|
||||
"\n",
|
||||
"[0.58264778] \n",
|
||||
"[0.32897483] \n",
|
||||
"\n",
|
||||
"[0.19358132 0.3565561 ] \n",
|
||||
"[0.96680953 0.76946094] \n",
|
||||
"\n",
|
||||
"[[0.32759701 0.74016873 0.83999783]\n",
|
||||
" [0.62572959 0.13477642 0.86937912]] \n",
|
||||
"[[0.0936316 0.2776172 0.16938396]\n",
|
||||
" [0.21494328 0.26245945 0.22463559]] \n",
|
||||
"\n",
|
||||
"[0.36292738 0.51118156 0.35250669] \n",
|
||||
"\n",
|
||||
"[[ 0.07101816 0.1111697 -0.89099377]] \n",
|
||||
"\n"
|
||||
]
|
||||
}
|
||||
@@ -176,7 +190,13 @@
|
||||
"z3 = np.random.random(2) #生成1×2的数组\n",
|
||||
"print(z3,\"\\n\")\n",
|
||||
"z4 = np.random.random((2,3)) #生成一个2行3列的数组\n",
|
||||
"print(z4,\"\\n\")"
|
||||
"print(z4,\"\\n\")\n",
|
||||
"\n",
|
||||
"z5 = np.random.rand(3) # 生成1×3的数组\n",
|
||||
"print(z5,\"\\n\")\n",
|
||||
"\n",
|
||||
"z6 = np.random.normal(0,1,(1,3))\n",
|
||||
"print(z6,\"\\n\")"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user