【发布时间】:2016-06-14 16:28:10
【问题描述】:
我有一个 pandas 数据框,其中包含从 0 到 1 的浮点数。
我想将此矩阵取幂为某个幂(例如 6)。
我开始使用scipy,但对于我的 7000x7000 矩阵而言,该操作需要非常非常长的时间,所以我认为这将是测试 tensorflow 的绝佳机会
如果符号是关于幻觉的,我深表歉意,我认为我输入的所有内容都正确。我想使用placeholder 和feed。
我的函数exp_corr 输入一个pandas 数据框对象,然后将矩阵取幂为某个整数的幂。
如何在 feed_dict 中使用占位符?
这是我的代码:
#Example DataFrame
L_test = [[0.999999999999999,
0.374449352805868,
0.000347439531148995,
0.00103026903356954,
0.0011830950375467401],
[0.374449352805868,
1.0,
1.17392596672424e-05,
1.49428208843456e-07,
1.216664263989e-06],
[0.000347439531148995,
1.17392596672424e-05,
1.0,
0.17452569907144502,
0.238497202355299],
[0.00103026903356954,
1.49428208843456e-07,
0.17452569907144502,
1.0,
0.7557000865939779],
[0.0011830950375467401,
1.216664263989e-06,
0.238497202355299,
0.7557000865939779,
1.0]]
labels = ['AF001', 'AF002', 'AF003', 'AF004', 'AF005']
DF_corr = pd.DataFrame(L_test,columns=labels,index=labels)
DF_signed = np.tril(np.ones(DF_corr.shape)) * DF_corr
数据框看起来像:
AF001 AF002 AF003 AF004 AF005
AF001 1.000000 0.000000e+00 0.000000 0.0000 0
AF002 0.374449 1.000000e+00 0.000000 0.0000 0
AF003 0.000347 1.173926e-05 1.000000 0.0000 0
AF004 0.001030 1.494282e-07 0.174526 1.0000 0
AF005 0.001183 1.216664e-06 0.238497 0.7557 1
我试过的矩阵指数函数:
#TensorFlow Computation
def exp_corr(DF_var,exp=6):
# T_feed = tf.placeholder("float", DF_var.shape) ?
T_con = tf.constant(DF_var.as_matrix(),dtype="float")
T_exp = tf.pow(T_con, exp)
#Initiate
init = tf.initialize_all_variables()
sess = tf.Session()
DF_exp = pd.DataFrame(sess.run(T_exp))
DF_exp.columns = DF_var.column; DF_exp.index = DF_var.index
sess.close()
return(DF_exp)
DF_exp = exp_corr(DF_signed)
【问题讨论】:
-
能否请您对速度增益发表评论?
标签: python numpy matrix tensorflow exponential