list 2 darray
In [39]: list=[1,2,3,4,5,6]
In [40]: type(list)
Out[40]: list
In [42]: array=np.array(list) //creare array by list
In [43]: type(array)
Out[43]: numpy.ndarray
ndarray to list
In [44]: list=array.tolist()
In [45]: list
Out[45]: [1, 2, 3, 4, 5, 6]
In [32]: n1 = np.array([1,2, 3, 4]).reshape(2, 2)
In [33]: n1
Out[33]:
array([[1, 2],
[3, 4]])
In [34]: n1.tolist()
Out[34]: [[1, 2], [3, 4]] 并不是 [1,2, 3, 4]
np.save("valid", [r_s, result_labels])
ValueError: could not broadcast input array from shape (610,3920) into shape (610)
ndarray to tensor
In [50]: t1 = tf.convert_to_tensor(np.array([1,2,3,4,5,6]), dtype=tf.float32)
In [51]: t1
Out[51]: <tf.Tensor: id=10, shape=(6,), dtype=float32, numpy=array([1., 2., 3., 4., 5., 6.], dtype=float32)>
tensor to ndarray
In [51]: t1
Out[51]: <tf.Tensor: id=10, shape=(6,), dtype=float32, numpy=array([1., 2., 3., 4., 5., 6.], dtype=float32)>
In [52]: t1.numpy()
Out[52]: array([1., 2., 3., 4., 5., 6.], dtype=float32)
在2.0中EeagerTensor的 eval()不行,但错误提示给出方法
/usr/local/lib/python2.7/dist-packages/tensorflow_core/python/framework/ops.pyc in eval(self, feed_dict, session)
1113 def eval(self, feed_dict=None, session=None):
1114 raise NotImplementedError(
-> 1115 "eval is not supported when eager execution is enabled, "
1116 "is .numpy() what you're looking for?")
1117
NotImplementedError: eval is not supported when eager execution is enabled, is .numpy() what you're looking for?
好多地方或者说所有的地方 ndarray 和tensor都是一样的不用转型
interpreter.set_tensor(input_index, np.reshape(x_train_rs[100],(1,128,3,1)))
tf.data.Dataset.from_tensor_slices((x_test_rs, y_test)).batch(1)
也许这也是说tensorflow2.0像 numpy的原因之一