在学习tf.truncated_normal的用法时出现ImportError: No module named 'matplotlib'错误,环境是spyder(tensorflow)。
开始我是怀疑matplotlib没有安装于是在cmd输入conda insatll matplotlib,不过问题还是没有解决。在stackoverflow里面发现了一个跟我的很像的问题点击打开链接以及一个在ubuntu下Tensorflow 报错: ImportError: No module named 'matplotlib'点击打开链接总结之后找到了我的解决方法(激活tensorflow之后再安装matplotlib)如下图:
附上检验代码:
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
c = tf.truncated_normal(shape=[10,10],mean=0,stddev=1)
with tf.Session() as sess:
print(sess.run(c))
runfile('C:/Users/Administrator/Desktop/tf.truncatte_numal.py', wdir='C:/Users/Administrator/Desktop')
[[-1.9203953 0.05469403 0.6080054 -0.69481444 -0.53585505 1.335796
1.243716 0.2108598 0.66066146 1.7688067 ]
[-0.281912 -0.04062371 0.5572222 0.18685326 -0.6207648 0.36795095
-0.15695563 -0.05966974 -1.7729266 -1.0577439 ]
[ 0.57240963 -0.2512155 -1.2736409 -1.1340874 1.6702118 0.11947601
-0.5802448 1.2095392 0.6952177 0.76556206]
[-0.6568331 0.65864515 -1.3606945 0.4191422 1.27515 0.06791862
-0.5316762 0.41110617 1.2422276 0.66298586]
[-0.698829 -1.765808 0.14666393 0.03730835 0.6220427 -0.24313319
0.2929117 0.03021981 0.08043118 0.44137084]
[ 0.44784045 -0.28034717 1.4131352 -0.42518148 -1.8570764 0.27609113
1.2007494 0.6268236 0.89111257 -0.39511248]
[-1.5214611 -0.23834164 -0.5141991 0.39206615 0.6303777 0.2010414
0.7811891 -0.41266575 0.2629861 -0.08806221]
[-0.33817083 0.3833139 -0.04158774 -0.10101858 -0.08422951 0.8182789
0.24413791 -0.20389517 0.04668551 1.0764339 ]
[ 1.2552118 0.67300165 -0.422162 0.97278994 0.27860692 0.3610051
-0.7014023 0.08916163 0.14875422 0.69259924]
[-0.6995988 1.9875689 -0.98069364 1.3558428 0.61226016 -0.01402848
-0.1640436 -0.76319116 -0.72386897 -0.8296277 ]]