!jupyter-kernelspec list
Available kernels: ir /usr/local/share/jupyter/kernels/ir python2 /usr/local/share/jupyter/kernels/python2 python3 /usr/local/share/jupyter/kernels/python3 swift /usr/local/share/jupyter/kernels/swift
%load_ext rpy2.ipython
Betöltöttük a szükséges kiterjesztést.
%%R
x <- 42
print(x)
a <- 1;
b <- -1;
print(a+b)
c <- 1:2;
d <- 1:3;
c(c,d)
# getwd()
[1] 42 [1] 0 [1] 1 2 1 2 3
%matplotlib inline
Colab-on a matplotlib használat betöltése (Impont)
import numpy as np
x = np.linspace(0, 10, 100)
fig = plt.figure()
plt.plot(x, np.sin(x), '-')
plt.plot(x, np.cos(x), '--')
[<matplotlib.lines.Line2D at 0x7fcecfaa3eb8>]
Python rajzolás
plt.plot(x, np.sin(x - 0), color='blue') # specify color by name
plt.plot(x, np.sin(x - 1), color='g') # short color code (rgbcmyk)
plt.plot(x, np.sin(x - 2), color='0.75') # Grayscale between 0 and 1
plt.plot(x, np.sin(x - 3), color='#FFDD44') # Hex code (RRGGBB from 00 to FF)
plt.plot(x, np.sin(x - 4), color=(1.0,0.2,0.3)) # RGB tuple, values 0 to 1
plt.plot(x, np.sin(x - 5), color='chartreuse'); # all HTML color names supported
Python rajzolás 1
plt.plot(x, np.sin(x), '-g', label='sin(x)')
plt.plot(x, np.cos(x), ':b', label='cos(x)')
plt.axis('equal')
plt.legend();
Python rajzolás 2
# !pip install tensorflow # Istallálás ezzel lehet
import tensorflow as tf
tf.test.gpu_device_name()
a = tf.constant(1, name='a_var')
b = tf.constant(2, name='b_bar')
x = tf.placeholder(dtype=tf.float32, shape=(None, 1))
y_true = tf.placeholder(dtype=tf.float32, shape=(None, 1))
Tensort hasznáalat
%matplotlib inline
import math
import numpy as np
import matplotlib.pyplot as plt
theta = np.arange(0, 4 * math.pi, 0.1)
eight = plt.figure()
axes = eight.add_axes([0, 0, 1, 1])
axes.plot(0.5 * np.sin(theta), np.cos(theta / 2))
[<matplotlib.lines.Line2D at 0x7fceafeaccf8>]
Parancssor Bash Shell használata a Colab-ban
%%bash
python -c "print(2 * 4)"
echo "print(2 * 4)" > eight.py # Fájlba kiirás
python eight.py Fálból beolvasás végrahajtás
8 8
Ez egy másik meghivási szintektika állományba kiirás és futtatásra
%%writefile fourteen.py
#! /usr/bin/env python
print(2 * 7)
Writing fourteen.py
Környezet beállitása után futtatás
%%bash
chmod u+x fourteen.py # jog beállytása
./fourteen.py # futtatás
14
Komplex példa python program kiirása
%%writefile draw_eight.py
import math
import numpy as np
import matplotlib.pyplot as plt
def make_figure():
theta = np.arange(0, 4 * math.pi, 0.1)
eight = plt.figure()
axes = eight.add_axes([0, 0, 1, 1])
axes.plot(0.5 * np.sin(theta), np.cos(theta / 2))
return eight
Writing draw_eight.py
Használat
import draw_eight
image = draw_eight.make_figure()
import geopy
geocoder = geopy.geocoders.Yandex(lang="en_US")
geocoder.geocode('Cambridge', exactly_one=False)
def geolocate(place):
return geocoder.geocode(place, exactly_one = False)[0][1]
print(geolocate('Cambridge') )
london_location = geolocate("London")
import requests
def request_map_at(lat, long, satellite=True, zoom=10, size=(400, 400)):
base = "https://static-maps.yandex.ru/1.x/?"
params = dict(
z = zoom,
size = str(size[0]) + "," + str(size[1]),
ll = str(long) + "," + str(lat),
l = "sat" if satellite else "map",
lang = "en_US" )
return requests.get(base,params=params)
def map_at(*args, **kwargs):
return request_map_at(*args, **kwargs).content
print(london_location)
import IPython
map_png = map_at(*london_location)
print("The type of our map result is actually a: ", type(map_png))
IPython.core.display.Image(map_png)
(52.20532, 0.121794) (51.507351, -0.12766) The type of our map result is actually a: <class 'bytes'>