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
394 changes: 364 additions & 30 deletions Sounak97.ipynb
Original file line number Diff line number Diff line change
@@ -1,32 +1,366 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Sounak97.ipynb",
"version": "0.3.2",
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
}
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
"cells": [
{
"metadata": {
"id": "ahm2qZERkD2t",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 168
},
"outputId": "c840c130-e0b3-422d-dab3-a9515a47bcdf"
},
"cell_type": "code",
"source": [
"#1) Create any random list and assign it to a variable dummy_list\n",
"dummy_list=[100,300,200,500,400]\n",
"print(dummy_list)#2) print dummy_list\n",
"dummy_list.reverse()\n",
"print(dummy_list)#3) Reverse dummy_list and print\n",
"dummy_list_2 = [2, 200, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02]\n",
"dummy_list=dummy_list + dummy_list_2#4) Add the list dummy_list_2 to the previous dummy_list and now print dummy_list\n",
"print(dummy_list)\n",
"dummy_dict={100:1,300:1,200:2,500:1,400:1,2:1,16:1,4:1,1:1,0:1,9.45:1,45.67:1,90:1,12.01:1,12.02:1}\n",
"\n",
"print(dummy_dict) #5) Create a dictionary named dummy_dict which contains all the elements of dummy_list as keys and frequency as values.6) print dummy_dict\n",
"dummy_list.sort()#7) Sort dummy_list in ascending order as well as descending order and print the changed lists\n",
"print(dummy_list)\n",
"dummy_list.sort(reverse=True)\n",
"print(dummy_list)\n",
"x=200#8) Remove the first item from the list whose value is equal to x. It raises a ValueError if there is no such item.\n",
"p=0\n",
"j=0\n",
"for j in dummy_list:\n",
" if j==x :\n",
" dummy_list.remove(j)\n",
" break\n",
" else:\n",
" j=j+1\n",
" p=p+1\n",
" \n",
"if p==len(dummy_list):\n",
" print(\"ValueError\")\n",
"else:\n",
" print(dummy_list)\n",
" \n",
"x=14#9) Remove the item at position x. x is any random integer\n",
"if(x>len(dummy_list)):\n",
" print(\"Out of Range\")\n",
"else:\n",
" del dummy_list[x]\n",
"print(dummy_list)\n",
"del dummy_list[:]#10) Let's clean everything clear the list and then print\n",
"print(dummy_list)\n",
"\n",
"\n",
" \n",
" \n",
"\n"
],
"execution_count": 2,
"outputs": [
{
"output_type": "stream",
"text": [
"[100, 300, 200, 500, 400]\n",
"[400, 500, 200, 300, 100]\n",
"[400, 500, 200, 300, 100, 2, 200, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02]\n",
"{100: 1, 300: 1, 200: 2, 500: 1, 400: 1, 2: 1, 16: 1, 4: 1, 1: 1, 0: 1, 9.45: 1, 45.67: 1, 90: 1, 12.01: 1, 12.02: 1}\n",
"[0, 1, 2, 4, 9.45, 12.01, 12.02, 16, 45.67, 90, 100, 200, 200, 300, 400, 500]\n",
"[500, 400, 300, 200, 200, 100, 90, 45.67, 16, 12.02, 12.01, 9.45, 4, 2, 1, 0]\n",
"[500, 400, 300, 200, 100, 90, 45.67, 16, 12.02, 12.01, 9.45, 4, 2, 1, 0]\n",
"[500, 400, 300, 200, 100, 90, 45.67, 16, 12.02, 12.01, 9.45, 4, 2, 1]\n",
"[]\n"
],
"name": "stdout"
}
]
},
{
"metadata": {
"id": "VwSRD8sVvAFC",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 857
},
"outputId": "371e4abd-fa21-42eb-9804-cb9be93e584e"
},
"cell_type": "code",
"source": [
"import numpy as np#Import numpy\n",
"a=np.array([100,200,300])\n",
"print(a)\n",
"print(type(a))\n",
"\n",
"b=np.array([[10,20,30],[40,50,60]]) #Create numpy arrays\n",
"print(b.shape)\n",
"print(b[0,0],b[0,1],b[1,0])\n",
"a=np.zeros(shape=(2,2))#Some basic functions for creating arrays\n",
"b=np.ones(shape=(3,3))\n",
"c=np.eye(2)\n",
"d=np.full(shape=(3,3),fill_value=5)\n",
"e=np.random.random((2,2))\n",
"print('a',a)\n",
"print('b',b)\n",
"print('c',c)\n",
"print('d',d)\n",
"print('e',e)\n",
"a==np.arange(10) #execute and understand\n",
"b==np.linspace(0,10,num=6)\n",
"print(a)\n",
"print(b)\n",
"a = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]])#Array Indexing\n",
"b = a[:2, 1:3]\n",
"print(a[0,1])\n",
"b[0,0]=77\n",
"print(a[0,1])\n",
"a = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]])#slicing\n",
"row_r1 = a[1, :] \n",
"row_r2 = a[1:2, :]\n",
"print(row_r1,row_r1.shape)\n",
"print(row_r2,row_r2.shape)\n",
"col_r1=a[:,1]\n",
"col_r2=a[:,1:2]\n",
"print(col_r1, col_r1.shape)\n",
"print(col_r2, col_r2.shape)\n",
"\n",
"\n",
"x=np.array([[1,2],[3,4]])#Arithmetic operations\n",
"print(np.sum(x))\n",
"print(np.sum(x,axis=0))#sum of each column\n",
"print(np.sum(x,axis=1))#sum of each row\n",
"b=np.arange(10)#Boolean Mask use\n",
"print(b)\n",
"mask=b%2!=0\n",
"print(mask)\n",
"print(b[mask])\n",
"mod_b=b\n",
"mod_b[mask]=-1\n",
"print(mod_b)\n",
"a=np.arange(9).reshape(3,3)#swapping 2 colums\n",
"print(a)\n",
"print(a[:,[1,0,2]])\n",
"a=np.arange(9).reshape(3,3)#swapping 2 rows\n",
"print(a)\n",
"print(a[[1,0,2],:])\n",
"\n"
],
"execution_count": 0,
"outputs": [
{
"output_type": "stream",
"text": [
"[100 200 300]\n",
"<class 'numpy.ndarray'>\n",
"(2, 3)\n",
"10 20 40\n",
"a [[0. 0.]\n",
" [0. 0.]]\n",
"b [[1. 1. 1.]\n",
" [1. 1. 1.]\n",
" [1. 1. 1.]]\n",
"c [[1. 0.]\n",
" [0. 1.]]\n",
"d [[5 5 5]\n",
" [5 5 5]\n",
" [5 5 5]]\n",
"e [[0.58957867 0.78449677]\n",
" [0.17984702 0.68954991]]\n",
"[[0. 0.]\n",
" [0. 0.]]\n",
"[[1. 1. 1.]\n",
" [1. 1. 1.]\n",
" [1. 1. 1.]]\n",
"2\n",
"77\n",
"[5 6 7 8] (4,)\n",
"[[5 6 7 8]] (1, 4)\n",
"[ 2 6 10] (3,)\n",
"[[ 2]\n",
" [ 6]\n",
" [10]] (3, 1)\n",
"10\n",
"[4 6]\n",
"[3 7]\n",
"[0 1 2 3 4 5 6 7 8 9]\n",
"[False True False True False True False True False True]\n",
"[1 3 5 7 9]\n",
"[ 0 -1 2 -1 4 -1 6 -1 8 -1]\n",
"[[0 1 2]\n",
" [3 4 5]\n",
" [6 7 8]]\n",
"[[1 0 2]\n",
" [4 3 5]\n",
" [7 6 8]]\n",
"[[0 1 2]\n",
" [3 4 5]\n",
" [6 7 8]]\n",
"[[3 4 5]\n",
" [0 1 2]\n",
" [6 7 8]]\n"
],
"name": "stdout"
},
{
"output_type": "stream",
"text": [
"/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:19: DeprecationWarning: elementwise == comparison failed; this will raise an error in the future.\n",
"/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:20: DeprecationWarning: elementwise == comparison failed; this will raise an error in the future.\n"
],
"name": "stderr"
}
]
},
{
"metadata": {
"id": "JTnipVXrvLwo",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 638
},
"outputId": "b7a95e69-ccca-4dd9-cb68-57d7f287dcd7"
},
"cell_type": "code",
"source": [
"\n",
"\n",
"\n",
"import numpy as np#Create a uniform subdivision of the interval -1.3 to 2.5 with 64 subdivisions\n",
"A=np.linspace(-1.3,2.5,64)\n",
"print(A)\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"n=int(input())# Generate an array of length 3n filled with the cyclic pattern 1, 2, 3\n",
"B=np.array([1,2,3])\n",
"B=np.resize(B,3*n)\n",
"print(B)\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"b1=np.arange(1,20,2)#Create an array of the first 10 odd integers.\n",
"print(b1)\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"a=np.array([1,2,3,2,3,4,3,4,5,6])#Find intersection of a and b\n",
"b = np.array([7,2,10,2,7,4,9,4,9,8])\n",
"np.intersect1d(a,b)\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"a1=np.arange(10)# Reshape 1d array a to 2d array of 2X5\n",
"print(a1)\n",
"a1=a1.reshape(2,5)\n",
"print(a1)\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"a2=[1,2,3,4,5,6,7,8,9]#conversion\n",
"a2=np.array(a2)#numpy list to array\n",
"print(a2)\n",
"a2.tolist()#numpy array to list\n",
"print(a2)\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"a3=np.ones(shape=(10,10))# Create a 10 x 10 arrays of zeros and then \"frame\" it with a border of ones.\n",
"a3[1:9,1:9]=0\n",
"print(a3)\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"a4=np.ones(shape=(8,8))#Create an 8 x 8 array with a checkerboard pattern of zeros and ones using a slicing+striding approach.\n",
"a4[::2,1::2]=0\n",
"a4[1::2,::2]=0\n",
"print(a4)"
],
"execution_count": 0,
"outputs": [
{
"output_type": "stream",
"text": [
"[-1.3 -1.23968254 -1.17936508 -1.11904762 -1.05873016 -0.9984127\n",
" -0.93809524 -0.87777778 -0.81746032 -0.75714286 -0.6968254 -0.63650794\n",
" -0.57619048 -0.51587302 -0.45555556 -0.3952381 -0.33492063 -0.27460317\n",
" -0.21428571 -0.15396825 -0.09365079 -0.03333333 0.02698413 0.08730159\n",
" 0.14761905 0.20793651 0.26825397 0.32857143 0.38888889 0.44920635\n",
" 0.50952381 0.56984127 0.63015873 0.69047619 0.75079365 0.81111111\n",
" 0.87142857 0.93174603 0.99206349 1.05238095 1.11269841 1.17301587\n",
" 1.23333333 1.29365079 1.35396825 1.41428571 1.47460317 1.53492063\n",
" 1.5952381 1.65555556 1.71587302 1.77619048 1.83650794 1.8968254\n",
" 1.95714286 2.01746032 2.07777778 2.13809524 2.1984127 2.25873016\n",
" 2.31904762 2.37936508 2.43968254 2.5 ]\n",
"6\n",
"[1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3]\n",
"[ 1 3 5 7 9 11 13 15 17 19]\n",
"[0 1 2 3 4 5 6 7 8 9]\n",
"[[0 1 2 3 4]\n",
" [5 6 7 8 9]]\n",
"[1 2 3 4 5 6 7 8 9]\n",
"[1 2 3 4 5 6 7 8 9]\n",
"[[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]\n",
" [1. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n",
" [1. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n",
" [1. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n",
" [1. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n",
" [1. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n",
" [1. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n",
" [1. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n",
" [1. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n",
" [1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]]\n",
"[[1. 0. 1. 0. 1. 0. 1. 0.]\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",
" [1. 0. 1. 0. 1. 0. 1. 0.]\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"
],
"name": "stdout"
}
]
},
{
"metadata": {
"id": "5mZI6Q3q1cCb",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
""
]
}
]
}
Loading