Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Introduction-to-Python
Submodule Introduction-to-Python added at eda4e5
61 changes: 48 additions & 13 deletions NumPy/1. Data Types.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -502,10 +502,23 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[260]\n"
]
}
],
"source": [
"import numpy as np\n",
"arr = np.array([250], dtype=np.int16)\n",
"arr.dtype\n",
"print(arr + 10)"
]
},
{
"cell_type": "markdown",
Expand All @@ -525,10 +538,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"8000000\n",
"2000000\n",
"4.0\n"
]
}
],
"source": [
"import numpy as np\n",
"arr = np.zeros([1000000], dtype=np.float64)\n",
"print(arr.nbytes)\n",
"arr2 = np.zeros([1000000], dtype=np.float16)\n",
"print(arr2.nbytes)\n",
"print(arr.nbytes / arr2.nbytes)"
]
},
{
"cell_type": "markdown",
Expand All @@ -550,21 +580,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 23,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The data type of the array is <U7\n",
"The updated array is ['Alexand' 'Bob' 'Charlie']\n",
"The re-created array is ['Alexandria' 'Bob' 'Charlie']\n",
"The data type of the array is <U11\n"
"<U7\n",
"['Alexandria' 'Bob' 'Charlie']\n"
]
}
],
"source": []
"source": [
"import numpy as np\n",
"arr = np.array([\"Alice\", \"Bob\", \"Charlie\"])\n",
"print(arr.dtype)\n",
"arr[0] = \"Alexandria\"\n",
"arr = np.array([\"Alexandria\", \"Bob\", \"Charlie\"], dtype='U10')\n",
"print(arr)"
]
},
{
"cell_type": "markdown",
Expand All @@ -576,7 +611,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "p310env",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand Down