# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python [default]
#     language: python
#     name: python3
# ---

import numpy as np

a = np.random.random((12,3,3))

a.size

b =np.array([1,2,3,4])
np.prod(b)

b.prod()

c = np.arange(20).reshape((4,5))

c

c.sum(axis = 0)

c.sum(axis = 1)

c.sum(axis = 1).shape

np.prod(c.shape)

d = np.arange(-12,13).reshape(5,5)

d

d * (d>0) 

d[:,np.newaxis].shape

e = np.array([1,2,3,4,4])
f = d[np.arange(5),e]

f

f[:,np.newaxis].shape #this is same as keepdims = True (this one is better any day)

import matplotlib.pyplot as plt
# %matplotlib inline

mu, sigma = 0, 0.1 # mean and standard deviation
s = np.random.normal(mu, sigma, 1000)
count, bins, ignored = plt.hist(s, 30, normed=True)
plt.plot(bins, 1/(sigma * np.sqrt(2 * np.pi)) *
               np.exp( - (bins - mu)**2 / (2 * sigma**2) ),
         linewidth=2, color='r')
plt.show()


np.random.normal(0.1,0.1,(2,2))

2**2

a = {'a':1,'b':2}

a.update({'c':3,'d':8})

a

'w'+str(2)

a = [1,2,3,4]

for i,j in enumerate(a):
    print (i,j)
    

a = np.arange(25).reshape((5,5))

a

np.mean(a,axis = 1)

np.mean(a,axis =0)

p = (2,3)

mask = (np.random.randn(*p) < 0.2)/0.2

q = np.arange(6).reshape(2,-1)

q

mask

q* mask

np.random.randn(*p)

a = (2,3,4,5)

a = tuple(list(a) + [2])

a

a[-1]

a[:-1]

a

b = np.arange(100).reshape(10,10)

b

b.shape

np.pad(b,(1,1),'constant')

np.pad(b,(0,1),'constant')

c = np.arange(64).reshape(4,4,4)

c.shape

c[0]

np.pad(c,(0,1),'constant').shape

np.pad(b,((0,),(1,)),'constant')

2/ 2

c = np.arange(100).reshape((10,2,5))

c

c.reshape(-1)

np.zeros((2,2))

c[1,:,:]



StarcoderdataJupyterScriptsDedupFiltered