Skip to content

Instantly share code, notes, and snippets.

c = np.array([[1,2] , [3,4]])
print(c)
#[Output]:
#[[1 2]
# [3 4]]
print(c.shape)
import numpy as np
a = np.array([1.,2.,3.])
print(a.shape)
b = np.array([[1.,2.,3.]])
print(b.shape)
#[output]:
#(3,)
#(1, 3)
@Robofied
Robofied / numpy_introduction2.py
Created February 12, 2019 16:35
Numpy Library
c = 0
tic = time.time()
for i in range(1000000):
c += a[i]*b[i]
toc = time.time()
print("For loop " + str(1000*(toc-tic)) + "ms")
#[Output]:
#For loop 1236.6154193878174ms
@Robofied
Robofied / numpy_introduction1.py
Created February 12, 2019 16:34
Numpy Library
#Import Numpy in Python
import numpy as np
a = np.random.rand(5,1)
print(a)
#[Output]:
#[[0.28642857]
# [0.51330181]
@Robofied
Robofied / intermediate_python_special_methods2.py
Last active February 10, 2019 11:48
Intermediate Python
## Creating a cutom class with a special method __specialprint__
class custom_class:
def __init__(self, name):
self.name = name
## Creating a special method which is just printing the name associated with the object
  def __specialprint__(self):
print(self.name)
## Creating the object
## Creating a range object
x = range(4)
## Printing that object
x
#[Output]:
#range(0, 4)
#Here, there is no next method associated with the range object.
#But if we will create a generator using range object then next()function will work because the generator has special method next.
## Creating a string variable
b = 'Learn!'
## In this string value case str is giving output without '' but repr is giving output with ''
print(str(b))
#[Output]:
#Learn!
## In this string value case str is giving output without '' but repr is giving output with ''
## Creating a variable contains numerical value
a = 1/9
## printing that variable using str() then it will give simple output
## In this numerical value case both str and repr are giving same results.
print(str(a))
#[Output]:
@Robofied
Robofied / log_file.log
Created February 10, 2019 08:21
Intermediate Python
INFO:root:office_hours function ran with args ('10:00', '18:00') and kwargs {}
INFO:root:new_employee function ran with args () and kwargs {}
@Robofied
Robofied / intermediate_python_logging3.py
Created February 10, 2019 08:20
Intermediate Python
@ company
def new_employee():
print('Hi! Welcome to Robofied team')
## This function will also work fine as our function can handle any no. of arguments - zero, one, two etc..
new_employee()
#[Output]:
#Hi! Welcome to Robofied team