np plot linear regression torch
np plot linear regression torch
import numpy as np
#import simsimd; print(simsimd.get_capabilities())
print(arr)
print(type(arr))
sc = np.array((42,34) )
arr = np.array([1,8, 3, 4, 5])
print(sc)
print(type(sc))
print(arr)
a = np.array(42)
b = np.array([1, 2, 3, 4, 5])
c = np.array([[1, 2, 3], [4, 5, 6]])
d = np.array([[[1, 2, 3], [4, 5, 6]], [[1, 2, 3], [4, 5, 6]]])
print(a.ndim)
print(b.ndim)
print(c.ndim)
print(d.ndim)
print(arr)
print('number of dimensions :', arr.ndim)
print(arr[2] + arr[3])
arr = np.array([[1,2,3,4,5], [6,7,8,9,10]])
print(arr[1:5])
arr = np.array([1, 2, 3, 4, 5, 6, 7])
print(arr[4:])
print(arr[-3:-1])
print(arr[::5])
print(arr[0:2, 2])
print(arr[0:2, 1:4])
print(arr.dtype)
print(arr.dtype)
arr = np.array(["apple", "banana", "cherry"])
print(arr.dtype)
print(arr)
print(arr.dtype)
rrr = arr.astype('i')
print(rrr)
print(rrr.dtype)
nr = arr.astype(bool)
print(nr)
x = arr.copy()
y = arr.view()
print(x.base)
print(y.base)
import timeit
def test(n):
return sum(range(n))
n = 10000
loop = 10000
print(arr)
print('shape of array :', arr.shape)
import numpy as np
import matplotlib.pyplot as plt
import scipy.optimize
def sigmoid(p,x):
x0,y0,c,k=p
y = c / (1 + np.exp(-k*(x-x0))) + y0
return y
plt.xlabel('x')
plt.ylabel('y')
plt.grid(True)
plt.show()
Z=y
Z = np.array([3,1.75,-2,0.5] )
#[.95,.85,.12,.62]) [0.72709942 0.20831747 0.00489916 0.05968395]
A = 1 / (1 + (np.exp((-Z))))
#print (A)
t1 = time.time() #.process_time()
print('timeit',result)
print (t1-t0)
print ("dot operation = ." + "\n Computation time = " + str(1000*(t1 - t0)) +
"ms")
t0 = time.time() #.process_time()
tmatrix1 = [1.,2.,3.,4.,5.]
#array2
tmatrix2 = [6.,7.,8.,9.,10.]
for j in range(1000):
dot = 0
for i in range(len(tmatrix1)):
dot+= tmatrix1[i]*tmatrix2[i]
t1 = time.time() #.process_time()
print (t1-t0)
print ("dot operation = " + str(dot) + "\n Computation time = " + str(1000*(t1 -
t0)) + "ms")
import numpy as np
import matplotlib.pyplot as plt
def sig(x):
return 1/(1 + np.exp(-x))
# Sample data
x = np.array([1, 200, 30, 4, 5])
y = [2, 300, 55, 7, 11]
print(f"Slope: {slope}")
print(f"Intercept: {intercept}")
plt.plot(x, y,'bo')
plt.plot(x, slope*x+intercept, 'r-')
#plt.show()
plt.show()
import numpy as np
import matplotlib.pyplot as plt
x = np.array([0.1, 0.2, 0.4, 0.6, 0.8, 1.0, 2.0, 4.0, 6.0, 8.0, 10.0,
20.0, 40.0, 60.0, 80.0])
print(a)
plt.plot(x, y, 'bo')
plt.plot(x, y)
#plt.plot(x, x,'go')
plt.plot(x, a*x, 'r-')
plt.show()