larger sample than population when replace is False

This commit is contained in:
2023-06-11 11:49:15 +08:00
parent 49d3c6791e
commit 5387268d48
3 changed files with 128 additions and 48 deletions

View File

@@ -239,6 +239,33 @@
" )\n",
"print(lst_choose_firm)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"ename": "ValueError",
"evalue": "Cannot take a larger sample than population when replace is False",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[1;32mIn[9], line 2\u001b[0m\n\u001b[0;32m 1\u001b[0m nprandom \u001b[39m=\u001b[39m np\u001b[39m.\u001b[39mrandom\u001b[39m.\u001b[39mdefault_rng(\u001b[39m0\u001b[39m)\n\u001b[1;32m----> 2\u001b[0m lst_choose_firm \u001b[39m=\u001b[39m nprandom\u001b[39m.\u001b[39;49mchoice([\u001b[39m1\u001b[39;49m,\u001b[39m2\u001b[39;49m],\n\u001b[0;32m 3\u001b[0m \u001b[39m3\u001b[39;49m,\n\u001b[0;32m 4\u001b[0m replace\u001b[39m=\u001b[39;49m\u001b[39mFalse\u001b[39;49;00m\n\u001b[0;32m 5\u001b[0m )\n\u001b[0;32m 6\u001b[0m lst_choose_firm\n",
"File \u001b[1;32m_generator.pyx:753\u001b[0m, in \u001b[0;36mnumpy.random._generator.Generator.choice\u001b[1;34m()\u001b[0m\n",
"\u001b[1;31mValueError\u001b[0m: Cannot take a larger sample than population when replace is False"
]
}
],
"source": [
"nprandom = np.random.default_rng(0)\n",
"lst_choose_firm = nprandom.choice([1,2],\n",
" 3,\n",
" replace=False\n",
" )\n",
"lst_choose_firm"
]
}
],
"metadata": {