PYTHON NOTES
PYTHON NOTES
FILE DIRECTORIES:
Import os
Print(os.getcwd()) {current working directory)
Print(os.getcwdb()) {current working directory in bytes)
os.mkdir(‘..’) {makes a new directory at that location with the given name}
os.rename(‘..’, ‘..’)
os.rmdir(‘..’) {to remove a directory}
os.remove(‘..’) {to remove a file}
list = [1,2,3,4,5]
our_iter = iter(list)
print(next(our_iter))
print(our_iter.__next__())
class powoftwo():
'''the power of 2 is as follows'''
def __init__(self, max=0):
self.max = max
def __iter__(self):
self.num = 0
return self
def __next__(self):
if self.num <= self.max:
result = 2**self.num
self.num += 1
return result
else:
raise StopIteration
print(powoftwo.__doc__)
a = powoftwo(16)
i = iter(a)
print(next(i))
print(next(i))
print(next(i))
print(next(i))
print(next(i))
NUMPY NOTES:
A = np.array([1,2,3]) to make a one dimensional array.
C = np.array([[1,2,3], [4,5,6], [7,8,9]]) to make a two dimensional array
a.ndim to get the dimension
a.size to find the number of elements
a.shape to know the shape
a.dtype to know the datatype of the elements
np.zeros(b) to create an array with b zeroes
np.ones(b) to create an array with b ones.
Np.empty(b) to create an array with random b elements.
Np.arange(b) creates an array with elements from 0 to b-1.
Np.arange(a,b,c) a is first number, b is last and c is the common difference
between the elements of the array to be created.
Np.linspace(a,b,c) c signifies the number of elements u need within the range a
and b(included) all equally spaced from each other.
Np.sort(a) to sort the elements of the array a in ascending order.
Np.concatenate((a,b)) to join the arrays a and b.
Np.newaxis will increase the dimensions of your array by one dimension when
used once