借助 Colaboratory,您只需点击一下鼠标,即可在浏览器中执行 TensorFlow 代码。下面的示例展示了两个矩阵相加的情况。
$\begin{bmatrix}
In [0]:
import tensorflow as tf
input1 = tf.ones((2, 3))
input2 = tf.reshape(tf.range(1, 7, dtype=tf.float32), (2, 3))
output = input1 + input2
with tf.Session():
result = output.eval()
result
Out[0]:
您可以通过依次转到“文件”>“在 GitHub 中保存一份副本…”,保存一个 Colab 笔记本副本
只需在 colab.research.google.com/github/ 后面加上路径,即可在 GitHub 上加载任何 .ipynb。例如, 将在 GitHub 上加载此 .ipynb。
Colaboratory 包含很多已被广泛使用的库(例如 matplotlib),因而能够简化数据的可视化过程。
In [0]:
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(20)
y = [x_i + np.random.randn(1) for x_i in x]
a, b = np.polyfit(x, y, 1)
_ = plt.plot(x, y, 'o', np.arange(20), a*np.arange(20)+b, '-')
想使用新的库?请在笔记本的顶部通过 pip install
命令安装该库。然后,您就可以在笔记本的任何其他位置使用该库。要了解导入常用库的方法,请参阅导入库示例笔记本。
In [0]:
!pip install -q matplotlib-venn
from matplotlib_venn import venn2
_ = venn2(subsets = (3, 2, 1))
Colab 支持连接本地计算机上的 Jupyter 运行时。有关详情,请参阅我们的文档。
In [0]:
import numpy as np
In [2]:
import tushare as ts
In [3]:
!pip install tushare
In [0]:
import tushare as ts
import tensorflow as tf
In [5]:
!pip install tushare
In [1]:
import os
import sys
import pandas as pd
import re
import matplotlib.pyplot as plt
import tushare as ts
import time
import numpy as np
## hengruiyiyao:601800,,hanruiguye 300618,300601 kangtai ,luoniushang:000735, hongchuanhuizhi:002930
# example of plot web_site:https://matplotlib.org/gallery/index.html
##sz3999006,601800,300732
###: 002460
df=ts.get_k_data('300033', start='2018-06-28', ktype='5')
df2=ts.get_k_data('603180', start='2018-06-28', ktype='5')
ax1 = plt.subplot2grid((8,2),(0,0),rowspan=5,colspan=1)
ax2 = plt.subplot2grid((8,2),(5,0),rowspan=3, colspan=1)
ax3 = plt.subplot2grid((8,2),(0,1),rowspan=5, colspan=1)
ax4 = plt.subplot2grid((8,2),(5,1),rowspan=3, colspan=1)
#df =df.set_index(df.date)
#ax3 = plt.subplot2grid((3, 3), (1, 0), colspan=2)
#ax4 = plt.subplot2grid((3, 3), (1, 2), rowspan=2)
#ax5 = plt.subplot2grid((3, 3), (2, 2), rowspan=1)
###################################
ax1.plot(df.index[0:30],df['close'].tail(30))
ax1.plot(df.index[0:30],df['open'].tail(30))
ax2.bar(df.index[0:15],df['volume'].tail(15))
####################
ax3.plot(df2.index[0:30],df2['close'].tail(30))
ax3.plot(df2.index[0:30],df2['open'].tail(30))
ax4.bar(df2.index[0:15],df2['volume'].tail(15))
ax1.grid(True)
#ax2.grid(True)
ax3.grid(True)
#ax4.grid(True)
#ax1.hist(log=False,color=['red','green'],label=['open','close'])
#print time.asctime()
#print int(time.time())
plt.show()
In [0]:
Add study web site:math https://blog.csdn.net/xianlingmao/article/details/7919597
In [0]: