2017-08-26 6 views
2

最初の投稿:)私が間違っていると私を撃たないでください!numpy型の引数でタプルを使用する

以下で形状を定義するためのより簡略な方法はありますか?それは動作しますが、ちょっと風が強く、動的ではありません。

def neural_net_image_input(image_shape): 
    """ 
    Return a Tensor for a batch of image input 
    : image_shape: Shape of the images (taken from CIFAR10) 
    : return: Tensor for image input. 
    """ 
    x = tf.placeholder(tf.float32, shape=[None, image_shape[0], image_shape[1], image_shape[2]], name='x') 
    return x 

私はSOなどのサイトで1時間ほど成功していませんでした。私は(私が理解してください)エラー

TypeError: int() argument must be a string, a bytes-like object or a number, not 'tuple' 

だから私の形状引数に受け入れられる形式にタプルを変更する方法があるが、最初にこれを試して、

shape = [None, image_shape] 

が、得たのですか?

答えて

3

使用タプルの追加:一般化を開梱することは私には新しいものであることを

shape=(None, *image_shape) 
+1

shape=(None,)+image_shape # or if you want to allow lists and other sequences for image_shape: shape=(None,)+tuple(image_shape) 

または反復可能アンパック一般化との最近のPythonのバージョンで。従来の 'I、J = ... 'アンパックを置き換える、有用なインデックス作成のケースを考えることができます。 'x [(None、*(...))]'となります。 – hpaulj

関連する問題