<jupyter_start><jupyter_text>Numpy BasicsSaket TiwariDate: 14 June 2019<jupyter_code>import numpy as np
a=np.arange(1,5,0.5)
a
b=np.array([[1,2,3],[4,5,6]])
b
c=np.arange(12)
c
c.reshape(3,4)
c.reshape(6,2)
c
#python list pass hua h..jisko array me convert kiya h
b=np.array([-1,0,1,100])
b
a=np.array([1,2,3])
a=a*2
a
a=np.array([-1,0,1.5,100],dtype='int8')
a=a*2
a
#since it cworks on C therefore all the data is converted into floating vALUE as in C data type must be same
#due to data overflow data changes to -56 as minimum data in int8(8 bit integer)=-128 and maxm=127(range is from 0-127)
a[2:5]
a[::-1]
a=np.arange(12)
a
a[::2]
a[0]=100
a
a=a.reshape(3,4)
a
a[1:3, -1]
a[:,1:3]
c=np.arange(24).reshape(2,3,4)
c
c[1,1,1]
c[1,,]
c[1:,:,:]
c[1]<jupyter_output><empty_output><jupyter_text>Vectorization Vectorization Vectorization<jupyter_code>a=np.arange(12)
a
b=a.reshape(3,4)
b
a*2
#numpy is a vectorized library
b*2
a+2
a**2
b**2
a>6
a=np.arange(12)
b=np.arange(12)
a*b
a.reshape(3,4)*b.reshape(3,4)
a.dot(b)
a.shape
a.reshape(1,12)
A=a.reshape(1,12)
a
A

B=b.reshape(1,12)
B
B.T
A.dot(B.T)
B.T.dot(A)<jupyter_output><empty_output><jupyter_text>Masking<jupyter_code>a=np.arange(30)
a[a>15]
a=np.arange(30).reshape(5,6)
a
a[a>15].reshape(7,2)
a=np.arange(12)
a.flags
b=a.reshape(3,4)
b.flags
c=a[:5]
c.flags
a[0]=100
a
b
c
#a orignally makes the data and specifications of a is written in a header
#if we create b by changing specificcations of a, only another header is formed without changing of orignal data
#if there is any change in a made aftr, change in b is automatic
a[a>15]
a.flags
#only in masking the new data is formed
a=np.arange(12).reshape(3,4)
a
a.reshape(12,)
a.flatten()
a
a.reshape(6,-1)
a.reshape(-1)<jupyter_output><empty_output><jupyter_text>Special Arrays<jupyter_code>a=np.zeros((3,4),dtype='int8')
a
b=np.ones((3,4),dtype='int32')*5
b
np.empty((4,5))

np.identity(3)
np.eye(3,4)
np.linspace(1,5,7)
#creates 7 equal spaced no b/w 1 & 5<jupyter_output><empty_output><jupyter_text>Analysis<jupyter_code>a=np.arange(12)
a
b=a.reshape(3,4)
b
a.max()
np.max(b,axis=0)
np.max(b,axis=1)
np.sum(b,axis=0)
np.sum(b,axis=1)
np.mean(b)
np.mean(b,axis=0)
np.mean(b,axis=1)
np.median(b,axis=1)
np.std(b)
np.std(b,axis=0)
np.std(b,axis=1)<jupyter_output><empty_output><jupyter_text>Distributions &Randoms<jupyter_code>s=90+ np.random.rand(4,3) *10
s
s.astype('int8')
import time
ticks=time.time()
ticks #Epoch time
#it is the time from 1st january 1973
#it is time zone independent
#random numbers can be generated using epoch time--> the input time which enters into the random function is called Seed
np.random.seed(100)
print(np.random.rand(1))
print(np.random.rand(1))
print(np.random.rand(1))
np.random.rand(1)
np.random.seed(100)
print(np.random.rand(1))
print(np.random.rand(1))
print(np.random.rand(1))
np.random.randint(50,60,5)
mu=100
sigma=15
s=np.random.normal(mu,sigma, 1000)
s
len(s[s>90])
len(s)
np.mean(s)
np.std(s)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1819402484055052, 'fraction_numerical': 0.07217186975495132, 'mean_word_length': 6.2682926829268295, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '298065', 'license': 'MIT', 'n_tokens_mistral': 1520, 'n_tokens_neox': 1447, 'n_words': 299, 'path': 'Basics/Numpy Basics.ipynb', 'repo_name': 'saket-iiitR/Machine-Learning-Works', 'size': '2979'}