将numpy数组转换为张量

时间:2018-09-08 06:19:05

标签: python numpy tensorflow

我刚刚开始学习使用tensorflow进行机器学习。我基本上是在尝试使用Iris数据集,我想做的就是将numpy数组转换为张量。所以我使用pandas.read_csv( ),然后将其转换为numpy数组,之后我想将其转换为张量。但是由于某些原因,这样做时会出错。

Following is the code :

import tensorflow as tf
import numpy as np
import pandas as pd
from sklearn.utils import shuffle

data =pd.read_csv('###filepath####')
data=shuffle(data)
print type(data)
print data.values
data=np.asarray(data)
print type(data)
data_tf1 = tf.convert_to_tensor(data)

The error displayed is as follows:
TypeError: Expected binary or unicode string, got 5.6

现在数据集由5行组成,其中4行是float类型,一个是字符串。该数据集的确被转换为numpy数组,我也能够检索值,但是将问题所在就在于张量。

我想知道的是: 可以将由具有不同数据类型的值组成的numpy数组转换为张量吗?

P.s:我知道可能有替代方法,我正在尽力解决所有这些问题,我只想知道我的查询是否有效,或者没有办法完成。

0 个答案:

没有答案