简体   繁体   中英

TypeError:__init__() got an unexpected keyword argument 'shape'

So, I am a novice in Tensorflow, I have just written a basic code to add two numbers mathematically using a computational graph but it's throwing an error that on running in IPython console :

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import numpy as np
import tensorflow as tf

a = tf.constant(3.0, dtype=tf.float32)
b = tf.constant(4.0)
total = a+b
print(a)
print(b)
print(total)
tf.Tensor("Const:0", dtype='f',shape=[1])
tf.Tensor("Const_1:0", dtype='f',shape =[1])
tf.Tensor("add:0", dtype='f',shape=[1])

Error :

TypeError: __init__() got an unexpected keyword argument 'shape'

please help & thanks in advance....

Reading this doc , I understood Tensor has no attribute shape, so you can't give a shape as parameter.

However, what you are looking for is probably TensorShape .

Take also a look to the Tensor class , may help you :)

tf.Tensor("Const:0", dtype='f',shape=[1])

in theis line the keword argument "shape=[1]" is the reason for error

when u create an object for

tf.Tensor ()

it will not have an argument "shape", please remove it and try agin

else if you need to use shape means use it like

tf.shape([1])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM