JLUspring 2018-09-27 12:45
浏览 439

tensorflow axis1越界

-*- coding: utf-8 -*-

#author JLU_GuanQQ
"""
Spyder Editor

This is a temporary script file.
"""

#step0 import module and generate dataset
import tensorflow as tf
import numpy as np
#import matplotlib.pyplot as plt
BATCH_SIZE=8
seed=2
#generate random numbers based on seed
rdnum=np.random.RandomState(seed)
x_true=rdnum.rand(32,2)
y_true=[[int(x1+x2<1)] for (x1,x2) in x_true]

#step1 define the input parameter output and the process of forward propagation of the network
x=tf.placeholder(tf.float32,shape=(None,2)) #input
y=tf.placeholder(tf.float32,shape=(None,1)) #output
w1=tf.Variable(tf.random_normal([2,3])) #parameter
w2=tf.Variable(tf.random_normal([3,1])) #parameter
a=tf.matmul(x,w1) #propagation
y_=tf.matmul(a,w2) #propagation

#step2 define loss_function and backforward propagation
loss_function=tf.reduce_mean(tf.square(y_-y))
train_step=tf.train.GradientDescentOptimizer(0.001).minimize(loss_function)

#step3 define session and begin to train
with tf.Session() as sess:
init_parameter=tf.global_variables_initializer() #initialize parameters
sess.run(init_parameter)
steps=20000 #define the number of training sessions
for i in range(steps):
start_position=(i*BATCH_SIZE)%32
end_position=start_position+BATCH_SIZE
sess.run(train_step,feed_dict={x:x_true[start_position,end_position],y:y_true[start_position,end_position]})

            最后一句话 index 8 is out of bounds for axis 1 with size 2
  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 oracle集群安装出bug
    • ¥15 关于#python#的问题:自动化测试
    • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
    • ¥15 教务系统账号被盗号如何追溯设备
    • ¥20 delta降尺度方法,未来数据怎么降尺度
    • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
    • ¥15 再不同版本的系统上,TCP传输速度不一致
    • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
    • ¥15 DIFY API Endpoint 问题。
    • ¥20 sub地址DHCP问题