a = 2;
b = -1;
c = 4;
d = 10.0;
e = a+b;
f = a-b;
g = a*b*c;
h = a/d;
print("The value of e is",e,"where a = ", a, " and b = ", b ,sep = ' ');
fid = open('arithematic.txt', 'w')
print("The value of e is",e,"where a = ", a, " and b = ", b ,sep = ' ', file = fid)
fid.close()
import numpy as np
a = np.ndarray(5, dtype=float)
a[0] = 5; # Indexing of an array starts from zero
a[1] = 10;
a[2] = 11;
a[3] = -2;
a[4] = 6;
print(a)
np.shape(a)
b = np.zeros(5, dtype=float);
print(b)
c = np.linspace(1.0, 2.0, num=5, retstep=True, endpoint=True) #Extremely important
print(c)
c = np.arange(1.0, 2.0, 0.25)
print(c)
d = np.logspace(1.0, 4.0, num=4, endpoint=True)
print(d)
e = np.random.normal(0, 1, 5)
print("array a is =", a, "array e is =",e);
b = a+e;
print(b);
c = a-e;
d = np.multiply(a,e); #element wise multiplication
f = np.divide(a, e); #element wise division
print(c);
print(d);
print(f);
c = 2*a;
print(a);
print(c);
c = np.linspace(1., 4., 4);
print("c = :",c)
d = np.logspace(1., 4., 4)
print("d = :", d)
e = 10**c;
print("e = :", e)
print(f)
f[2:-1]
f[-3:-1]
f[0::2]
h = np.random.uniform(0,1,10); # Random array of size 1x10 with a uniform distribution between 0 and 1
print(h);
k = h[2:8];
print(k);
print("First element:",k[0] ,"Last element:", k[-1])
print(k);
m = k>0.5; # This line checks whether the entries of array k are larger than 0.5. If yes, then that particular index of m gets a value of 1 (boolean for True) else m gets a value of zero
print(m);
m = k<0 # For logical false python gives Boolean False as output
print(m);
n = k[k>0.5];
print(n); # Find the values of k>0 and assign them to another array n
a = np.ndarray(shape=(2,2), dtype=float);
print(a);
a = np.zeros(shape=(4,4));
print(a);
b = np.random.uniform(0,1,(4,4));
print(b);
e = np.ones(shape=(4,4));
print(e);
f = np.multiply(b, e);
print(f);
f = b*e;
print (f);
f = np.dot(b, e);
print(f);
g = 2*f; print(g);
p = np.where(g>3);
print(p);
print(g[p]) # g[row values, column values]
print(g[g>3])