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
156 changes: 156 additions & 0 deletions Numpy/exercises.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "exercises.ipynb",
"version": "0.3.2",
"provenance": [],
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"[View in Colaboratory](https://colab.research.google.com/github/Said113/Machine-Learning/blob/master/Numpy/exercises.ipynb)"
]
},
{
"metadata": {
"id": "jTlLW6CdyQKo",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"# **NumPy Exercises for Data Analysis**"
]
},
{
"metadata": {
"id": "Fc-F34DryPjY",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"### 1. Import numpy as np and see the version ?"
]
},
{
"metadata": {
"id": "2FROXdSeykQo",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"import numpy as np\n",
"#np.version this just for show numpy Path \n",
"np.version.version"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "3gUCcUm_yrgf",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"### 2. How to create a 1D array?"
]
},
{
"metadata": {
"id": "kWkYCtoZykTE",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"#here you can solve this problem with many solutions\n",
"a=np.array([1,2,3,4,5]) #here you can pass any sequence like(tuble,list,dict,set)\n",
"b=np.arange(5)\n",
"c=np.array(range(1,6))\n",
"e=np.ones(5,\"int\")\n",
"f=np.zeros(5,dtype=\"int8\")\n",
"j=np.random.choice(2,5)"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "n5DnkuMsy_Tm",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"### 3. How to create a boolean array?\n",
"##### Q Create a 3×3 numpy array of all True’s !!"
]
},
{
"metadata": {
"id": "xsyqlkpaykSV",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"a=np.ones(9,dtype='bool').reshape(3,3)"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "FPpLU-YtzTp9",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"### 4 Extract all odd numbers from arr ?\n",
"##### arr=np.array([1,2,3,4,5,6,7,8,9])"
]
},
{
"metadata": {
"id": "FoLZzUi4zUBk",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"arr=np.array([1,2,3,4,5,6,7,8,9])\n",
"a=arr[::2]\n",
"b=arr[arr%2!=0]\n",
"c=np.where(arr%2!=0) #this statement if you want to know the positions of the elements"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "F7h9cfSB2h_8",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
""
],
"execution_count": 0,
"outputs": []
}
]
}
217 changes: 217 additions & 0 deletions exercises.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "exercises.ipynb",
"version": "0.3.2",
"provenance": [],
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"[View in Colaboratory](https://colab.research.google.com/github/Said113/Machine-Learning/blob/ex_said/exercises.ipynb)"
]
},
{
"metadata": {
"id": "jTlLW6CdyQKo",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"# **NumPy Exercises for Data Analysis**"
]
},
{
"metadata": {
"id": "Fc-F34DryPjY",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"### 1. Import numpy as np and see the version ?"
]
},
{
"metadata": {
"id": "2FROXdSeykQo",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34
},
"outputId": "9f89af6f-d785-45b4-df9a-784f268be604"
},
"cell_type": "code",
"source": [
"import numpy as np\n",
"#np.version this just for show numpy Path \n",
"np.version.version"
],
"execution_count": 2,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"'1.14.6'"
]
},
"metadata": {
"tags": []
},
"execution_count": 2
}
]
},
{
"metadata": {
"id": "3gUCcUm_yrgf",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"### 2. How to create a 1D array?"
]
},
{
"metadata": {
"id": "kWkYCtoZykTE",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"#here you can solve this problem with many solutions\n",
"a=np.array([1,2,3,4,5]) #here you can pass any sequence like(tuble,list,dict,set)\n",
"b=np.arange(5)\n",
"c=np.array(range(1,6))\n",
"e=np.ones(5,\"int\")\n",
"f=np.zeros(5,dtype=\"int8\")\n",
"j=np.random.choice(2,5)"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "n5DnkuMsy_Tm",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"### 3. How to create a boolean array?\n",
"##### Q Create a 3×3 numpy array of all True’s !!"
]
},
{
"metadata": {
"id": "xsyqlkpaykSV",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"a=np.ones(9,dtype='bool').reshape(3,3)"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "FPpLU-YtzTp9",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"### 4 Extract all odd numbers from arr ?\n",
"##### arr=np.array([1,2,3,4,5,6,7,8,9])"
]
},
{
"metadata": {
"id": "FoLZzUi4zUBk",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"arr=np.array([1,2,3,4,5,6,7,8,9])\n",
"a=arr[::2]\n",
"b=arr[arr%2!=0]\n",
"c=np.where(arr%2!=0) #this statement if you want to know the positions of the elements"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "jsnIR8CcC23h",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"### 5 How to replace items that satisfy a condition with another value in numpy array?\n",
"###### Q. Replace all odd numbers in arr with -1 "
]
},
{
"metadata": {
"id": "F7h9cfSB2h_8",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34
},
"outputId": "a1b20d98-c2d3-421f-e8d9-c51a0c578df5"
},
"cell_type": "code",
"source": [
"arr=np.array([1,2,3,4,5,6,7,8,9])\n",
"c=np.where(arr%2!=0)\n",
"arr[c]=-1\n",
"arr"
],
"execution_count": 3,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"array([-1, 2, -1, 4, -1, 6, -1, 8, -1])"
]
},
"metadata": {
"tags": []
},
"execution_count": 3
}
]
},
{
"metadata": {
"id": "J5NNN_PMDgEM",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
""
],
"execution_count": 0,
"outputs": []
}
]
}