"\u001b[1;32m<ipython-input-27-c0bd6cd82294>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Squaring the list results in an error\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mL\u001b[0m\u001b[1;33m**\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for ** or pow(): 'list' and 'int'"
]
}
],
"source": [
"print(\"Squaring the list results in an error\")\n",
"L**2"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"This is how list squaring actually works\n"
]
},
{
"data": {
"text/plain": [
"[1, 4, 9, 16, 25]"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print(\"This is how list squaring actually works\")\n",
"L2 = []\n",
"for e in L:\n",
" L2.append(e**2)\n",
"L2"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"While it works perfectly with numpy array\n"
]
},
{
"data": {
"text/plain": [
"array([1, 4, 9], dtype=int32)"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print(\"While it works perfectly with numpy array\")\n",
"A**2"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Getting square roots of all elements of numpy array\n"
]
},
{
"data": {
"text/plain": [
"array([1. , 1.41421356, 1.73205081])"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print(\"Getting square roots of all elements of numpy array\")\n",
"np.sqrt(A)"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Getting log of all elements of a numpy array\n"
]
},
{
"data": {
"text/plain": [
"array([0. , 0.69314718, 1.09861229])"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print(\"Getting log of all elements of a numpy array\")\n",