将节点连接加载到TensorFlow的最佳方法是什么?

时间:2017-09-22 18:22:49

标签: python numpy tensorflow

我有一个包含网络节点连接的文本文件

以下是文本文件的当前格式,其中每个节点ID连接到文件中单行上的另一个节点ID

points = tf.Variable(tf.random_uniform([N,2]))

我想将此网络加载到NumPy阵列中以执行KMean Clustering

执行KMean聚类的代码将NumPy数组作为输入:https://codesachin.wordpress.com/2015/11/14/k-means-clustering-with-tensorflow/

的最佳方法是什么?

a)存储网络连接信息(我可以控制)

b)将文件作为NumPy数组读入TensorFlow

更新:

以此代码为例:https://gist.github.com/dave-andersen/265e68a5e879b5540ebc

在第11行随机加载点

$('input.timepicker').click(function(){
    $('.ui-timepicker-viewport').scrollTop(1000);
})

如何从静态文件中加载这些点?

文件应该是特定格式还是text / csv是最佳选择? (我可以控制正在读取的文件的格式)

2 个答案:

答案 0 :(得分:1)

numpy.loadtxt()函数是将文本数据加载到NumPy数组中的最简单方法:

points_array = numpy.loadtxt(filename, dtype=numpy.int32)

答案 1 :(得分:0)

好的,我找到了一种适合我的方法,但仍然不能100%确定这是达到我想要的最佳方式。

使用此代码作为基础:https://gist.github.com/dave-andersen/265e68a5e879b5540ebc

在第11行,它随机加载点我使用mrry建议的numpy.loadtxt方法并将其传递给TensorFlow.constant_initializer,然后使用TensorFlow.get_variable将其转换为点

init = tf.constant_initializer(np.loadtxt('node_links.txt',skiprows=0))
points = tf.get_variable('points', shape = [902946, 2], initializer = init)
相关问题