In [1]:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
In [2]:
# from google.colab import drive

# drive.mount('/content/drive/')
#images_path='/content/drive/MyDrive/Colab Notebooks/zapatocaImage.jpeg'
#img = mpimg.imread(images_path)
#plt.imshow(img)
#plt.show()
In [3]:
def gaussiana(x,a,b,c):
  exponente = -(x-b)**2 / (2 * c**2)
  y = a * np.exp(exponente)
  return y
In [4]:
x = np.arange(-15,15,0.1)
y1 = gaussiana(x,4,-5,np.pi)
y2 = gaussiana(x,-3,-2,1)
y3 = gaussiana(x,1,2,4)
In [5]:
plt.plot(x,y1,"r-")
plt.plot(x,y2,"g--")
plt.plot(x,y3,"k-.")
Out[5]:
[<matplotlib.lines.Line2D at 0x7f7b6f218760>]
In [6]:
x = np.arange(0,5,0.1)
y = np.arange(0,7,0.1)
In [7]:
print(x.shape)
print(y.shape)
(50,)
(70,)
In [8]:
print(x)
[0.  0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.  1.1 1.2 1.3 1.4 1.5 1.6 1.7
 1.8 1.9 2.  2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.  3.1 3.2 3.3 3.4 3.5
 3.6 3.7 3.8 3.9 4.  4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9]
In [9]:
yy, xx = np.meshgrid(x,y)
In [10]:
print(xx.shape)
print(yy.shape)
(70, 50)
(70, 50)
In [11]:
print(xx)
[[0.  0.  0.  ... 0.  0.  0. ]
 [0.1 0.1 0.1 ... 0.1 0.1 0.1]
 [0.2 0.2 0.2 ... 0.2 0.2 0.2]
 ...
 [6.7 6.7 6.7 ... 6.7 6.7 6.7]
 [6.8 6.8 6.8 ... 6.8 6.8 6.8]
 [6.9 6.9 6.9 ... 6.9 6.9 6.9]]
In [12]:
print(yy)
[[0.  0.1 0.2 ... 4.7 4.8 4.9]
 [0.  0.1 0.2 ... 4.7 4.8 4.9]
 [0.  0.1 0.2 ... 4.7 4.8 4.9]
 ...
 [0.  0.1 0.2 ... 4.7 4.8 4.9]
 [0.  0.1 0.2 ... 4.7 4.8 4.9]
 [0.  0.1 0.2 ... 4.7 4.8 4.9]]
In [13]:
def gauss2D(x, y, a=1, b=0, c=1, x0=0, y0=0):
  exponente = -((x-x0)**2 + (y-y0)**2) / (2*c**2)
  z = a * np.exp(exponente) + b
  return z
In [14]:
a = 4
b = 2
c = 0.5
In [15]:
zz = gauss2D(xx,yy,a,b,c,2,3)
zz2 = gauss2D(xx,yy,-5,1,1,3.5,2.5)
In [16]:
plt.imshow(zz+zz2,cmap="gray")
plt.colorbar()
Out[16]:
<matplotlib.colorbar.Colorbar at 0x7f7b6e92b370>
In [17]:
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot_surface(xx,yy, zz+zz2, rstride=3, cstride=3, linewidth=1, antialiased=True,cmap="rainbow")
Out[17]:
<mpl_toolkits.mplot3d.art3d.Poly3DCollection at 0x7f7b6e8c03a0>
In [18]:
np.savetxt("valoresenz.txt",zz)
In [19]:
np.savetxt?
In [20]:
import pickle
In [21]:
A = np.random.randint(low=1,high=101,size=(5,5))
In [22]:
print(A)
[[66  8 92  1 91]
 [81 84 87 99 13]
 [88  2 77 15 82]
 [ 4 83 87 87 20]
 [16 36 49 57  1]]
In [23]:
file = open('miarchivo', 'wb')
pickle.dump(A, file)
file.close()
In [24]:
file = open('miarchivo', 'rb')
B = pickle.load(file)
file.close()
In [25]:
print(B)
[[66  8 92  1 91]
 [81 84 87 99 13]
 [88  2 77 15 82]
 [ 4 83 87 87 20]
 [16 36 49 57  1]]
In [26]:
np.savetxt?
In [ ]: