Learn data science and machine learning by building real-world projects on Jovian

# APafzal84/insaid-eda-to-ml-30-jan

8 months ago
In [1]:
import warnings
warnings.filterwarnings('ignore')
In [2]:
import numpy as np
In [3]:
np.__version__
Out[3]:
'1.19.2'
In [4]:
arr = np.array([1,2.5,3.6,35])
arr
Out[4]:
array([ 1. ,  2.5,  3.6, 35. ])
In [5]:
np.sum(arr)
Out[5]:
42.1
In [6]:
np.std(arr)
Out[6]:
14.160751215948963
In [7]:
np.mean(arr)
Out[7]:
10.525
In [8]:
arr.shape
Out[8]:
(4,)
In [9]:
np.ndim(arr)
Out[9]:
1
In [10]:
t = 100
print(t)
print(type(t))
100 <class 'int'>
In [11]:
t = (100)
print(t)
print(type(t))
100 <class 'int'>
In [12]:
t = (100,)
print(t)
print(type(t))
(100,) <class 'tuple'>
In [13]:
arr.shape
Out[13]:
(4,)
In [14]:
arr = np.array( [ [1,2], [3,4] ] )
In [15]:
arr
Out[15]:
array([[1, 2],
[3, 4]])
In [16]:
arr.shape
Out[16]:
(2, 2)
In [17]:
np.ndim(arr)
Out[17]:
2
In [18]:
arr[1][1]
Out[18]:
4
In [19]:
arr[1,1]
Out[19]:
4
In [20]:
arr[0]
Out[20]:
array([1, 2])
In [21]:
np.arange(5)
Out[21]:
array([0, 1, 2, 3, 4])
In [22]:
np.arange(12).reshape(3,4)
Out[22]:
array([[ 0,  1,  2,  3],
[ 4,  5,  6,  7],
[ 8,  9, 10, 11]])
In [24]:
np.arange(12).reshape(6,2)
Out[24]:
array([[ 0,  1],
[ 2,  3],
[ 4,  5],
[ 6,  7],
[ 8,  9],
[10, 11]])
In [25]:
np.arange(12).reshape(2,2,3) # Create 2 arrays of 2rows and 3 cols
Out[25]:
array([[[ 0,  1,  2],
[ 3,  4,  5]],

[[ 6,  7,  8],
[ 9, 10, 11]]])
In [28]:
np.arange(12).reshape(3,2,2)
Out[28]:
array([[[ 0,  1],
[ 2,  3]],

[[ 4,  5],
[ 6,  7]],

[[ 8,  9],
[10, 11]]])
In [31]:
np.arange(12).reshape(1,4,3)
Out[31]:
array([[[ 0,  1,  2],
[ 3,  4,  5],
[ 6,  7,  8],
[ 9, 10, 11]]])
In [32]:
np.ndim(np.arange(12).reshape(1,4,3))
Out[32]:
3
In [33]:
arr = np.arange(12).reshape(2,2,3)
In [34]:
arr
Out[34]:
array([[[ 0,  1,  2],
[ 3,  4,  5]],

[[ 6,  7,  8],
[ 9, 10, 11]]])
In [35]:
arr[0]
Out[35]:
array([[0, 1, 2],
[3, 4, 5]])
In [36]:
arr[0][1]
Out[36]:
array([3, 4, 5])
In [37]:
arr[0,1]
Out[37]:
array([3, 4, 5])
In [38]:
arr[0][1][2]
Out[38]:
5
In [42]:
z = arr[0]
z
Out[42]:
array([[0, 1, 2],
[3, 4, 5]])
In [44]:
z[:,1]
Out[44]:
array([1, 4])
In [45]:
data = np.array([ [11,22,33],[44,55,66],[77,88,99] ])
data
Out[45]:
array([[11, 22, 33],
[44, 55, 66],
[77, 88, 99]])
In [46]:
X = data[:,:-1]
X
Out[46]:
array([[11, 22],
[44, 55],
[77, 88]])
In [47]:
y = data[:,-1]
y
Out[47]:
array([33, 66, 99])
In [ ]: