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
132 changes: 65 additions & 67 deletions Questions/Excercise numpy .ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@
"metadata": {
"id": "LIP5u4zi0Nmg",
"colab_type": "code",
"outputId": "33b2d6e8-8f01-4ae8-baaf-e7b7144dff12",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 210
},
"outputId": "134a627c-b3fe-44de-80c4-e1aad6982509"
"height": 204
}
},
"source": [
"import numpy as np #import numpy\n",
"a = np.linspace(-1.3,2.5,64)\n",
"print(a)"
"b = np.linspace(-1.3,2.5,64)\n",
"print(b)"
],
"execution_count": 3,
"execution_count": 1,
"outputs": [
{
"output_type": "stream",
Expand Down Expand Up @@ -76,28 +76,28 @@
"metadata": {
"id": "4TxT66309n1o",
"colab_type": "code",
"outputId": "c7f9cd9b-c670-432d-ec41-3f47b522e0cb",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 70
},
"outputId": "bbc54490-654d-48b5-e67b-4b2259a4bb4a"
"height": 68
}
},
"source": [
"import numpy as np\n",
"a=np.array([1,2,3])\n",
"print (a)\n",
"n=input(\"Enter the array length : \")\n",
"b=np.resize(a,(3*int(n)))\n",
"s=np.array([1,2,3])\n",
"print (s)\n",
"ns=input(\"Enter the length of the array: \")\n",
"b=np.resize(s,(3*int(ns)))\n",
"print (b)"
],
"execution_count": 2,
"execution_count": 17,
"outputs": [
{
"output_type": "stream",
"text": [
"[1 2 3]\n",
"Enter the array length : 6\n",
"[1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3]\n"
"Enter the length of the array: 5\n",
"[1 2 3 1 2 3 1 2 3 1 2 3 1 2 3]\n"
],
"name": "stdout"
}
Expand All @@ -118,23 +118,23 @@
"metadata": {
"id": "ebhEUZq29r32",
"colab_type": "code",
"outputId": "16ac0d6e-0538-4a55-f6af-ef4c7d14074b",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34
},
"outputId": "9e141103-cd42-4d5e-eb81-2fad744e8d33"
}
},
"source": [
"import numpy as np\n",
"array=np.arange(1,10,2)\n",
"print(array) "
"a=np.arange(1,20,2)\n",
"print(a) "
],
"execution_count": 4,
"outputs": [
{
"output_type": "stream",
"text": [
"[1 3 5 7 9]\n"
"[ 1 3 5 7 9 11 13 15 17 19]\n"
],
"name": "stdout"
}
Expand All @@ -155,24 +155,24 @@
"metadata": {
"id": "gOlfuJCo-JwF",
"colab_type": "code",
"outputId": "c645e5d0-6880-4b90-a242-a04415ab2966",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34
},
"outputId": "8a61deea-16b2-4570-a9a3-a15592e0568e"
}
},
"source": [
"import numpy as np\n",
"array1 = np.array([1,2,3,2,3,4,3,4,5,6])\n",
"array2 = np.array([7,2,10,2,7,4,9,4,9,8])\n",
"print(np.intersect1d(array1,array2))"
"a1 = np.array([1,2,3,4,5])\n",
"a2 = np.array([5,6,7,4,5,3])\n",
"print(np.intersect1d(a1,a2))"
],
"execution_count": 7,
"execution_count": 5,
"outputs": [
{
"output_type": "stream",
"text": [
"[2 4]\n"
"[3 4 5]\n"
],
"name": "stdout"
}
Expand All @@ -193,19 +193,19 @@
"metadata": {
"id": "2E8b55_2Cjx5",
"colab_type": "code",
"outputId": "9561727d-d1d6-4957-ff3d-3c8e1e054a59",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 52
},
"outputId": "9561727d-d1d6-4957-ff3d-3c8e1e054a59"
}
},
"source": [
"import numpy as np\n",
"a = np.array([0,1, 2, 3, 4, 5, 6,7,8,9])\n",
"b = np.reshape(a,(2,5))\n",
"print(b)"
],
"execution_count": 8,
"execution_count": 0,
"outputs": [
{
"output_type": "stream",
Expand All @@ -224,31 +224,31 @@
"colab_type": "text"
},
"source": [
"6) Create a numpy array to list and vice versa"
"6) Change a numpy array to list and vice versa"
]
},
{
"cell_type": "code",
"metadata": {
"id": "TLWmsiiR0-T6",
"colab_type": "code",
"outputId": "71be9de2-b1e8-4c78-a0e3-fbfd9b605df1",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34
},
"outputId": "c9b67724-e858-4367-e411-4bceaf720157"
}
},
"source": [
"import numpy as np\n",
"array = np.array([0,1,2,3,4,5,6,7,8,9])\n",
"array = np.array([1,2,3,3,4,5,6,6,5,9])\n",
"print(array.tolist()) #array to list"
],
"execution_count": 20,
"execution_count": 6,
"outputs": [
{
"output_type": "stream",
"text": [
"[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n"
"[1, 2, 3, 3, 4, 5, 6, 6, 5, 9]\n"
],
"name": "stdout"
}
Expand All @@ -259,24 +259,24 @@
"metadata": {
"id": "DGcqFBR51jfh",
"colab_type": "code",
"outputId": "0e0ab628-6f45-4743-ced3-5e9e0b578e0f",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34
},
"outputId": "0710a28e-91c5-42ad-ebef-f29f2ee4fe30"
}
},
"source": [
"import numpy as np\n",
"list = [0,1,2,3,4,5,6,7,8,9]\n",
"array = np.array(list)\n",
"print(array) #list to array\n"
"list = [1,2,3,3,4,5,6,6,5,9]\n",
"a = np.array(list)\n",
"print(a) #list to array\n"
],
"execution_count": 23,
"execution_count": 9,
"outputs": [
{
"output_type": "stream",
"text": [
"[0 1 2 3 4 5 6 7 8 9]\n"
"[1 2 3 3 4 5 6 6 5 9]\n"
],
"name": "stdout"
}
Expand All @@ -297,27 +297,27 @@
"metadata": {
"id": "4bjP3JAc9vRD",
"colab_type": "code",
"outputId": "18cf9359-e895-436f-f5a8-ef61da17c75c",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 439
},
"outputId": "c6133be3-6ab5-4093-adb1-140e752eb782"
"height": 425
}
},
"source": [
"import numpy as np\n",
"x = np.zeros((10,10))\n",
"print(\"1st array(10x10):\")\n",
"print(x)\n",
"print(\"after framing:\")\n",
"x = np.pad(x, pad_width=1, mode='constant', constant_values=1)\n",
"print(x)"
"a = np.zeros((10,10))\n",
"print(\"Array of 10X10 before framing:\")\n",
"print(a)\n",
"print(\"Array of 10X10 after framing:\")\n",
"a = np.pad(a, pad_width=1, mode='constant', constant_values=1)\n",
"print(a)"
],
"execution_count": 11,
"execution_count": 12,
"outputs": [
{
"output_type": "stream",
"text": [
"1st array(10x10):\n",
"Array of 10X10 before framing:\n",
"[[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n",
" [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n",
" [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n",
Expand All @@ -328,7 +328,7 @@
" [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n",
" [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n",
" [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]]\n",
"after framing:\n",
"Array of 10X10 after framing:\n",
"[[1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]\n",
" [1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n",
" [1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n",
Expand Down Expand Up @@ -361,27 +361,25 @@
"metadata": {
"id": "No7fx0Xy9zEh",
"colab_type": "code",
"outputId": "8c4fcd58-104c-48c3-e89e-0387e7caf3b5",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 175
},
"outputId": "4221ede7-f391-4b0f-f1af-939948521411"
"height": 153
}
},
"source": [
"import numpy as np\n",
"x = np.ones((3,3))\n",
"print(\"Checkerboard pattern:\")\n",
"x = np.zeros((8,8),dtype=int)\n",
"x[1::2,::2] = 1\n",
"x[::2,1::2] = 1\n",
"print(x)"
"a = np.ones((3,3))\n",
"a = np.zeros((8,8),dtype=int)\n",
"a[1::2,::2] = 1\n",
"a[::2,1::2] = 1\n",
"print(a)\n"
],
"execution_count": 12,
"execution_count": 28,
"outputs": [
{
"output_type": "stream",
"text": [
"Checkerboard pattern:\n",
"[[0 1 0 1 0 1 0 1]\n",
" [1 0 1 0 1 0 1 0]\n",
" [0 1 0 1 0 1 0 1]\n",
Expand Down
Loading