CNTK icon indicating copy to clipboard operation
CNTK copied to clipboard

Prepending singleton axis with expand_dims

Open jsundh opened this issue 8 years ago • 3 comments

There doesn't seem to be a way of prepending a singleton axis using the new expand_dims operation.

If I understand correctly, the semantics of the axis parameter is insert after (add at). If it instead was insert at, that would allow prepending which I think would be pretty nice to have:

i = C.placeholder((7, 5))
C.expand_dims(i, axis=0)  # [1, 7, 5] with "insert at"

I understand that such a change wouldn't be backwards compatible and therefore might not be possible to do.

jsundh avatar Feb 16 '18 12:02 jsundh

How about C.expand_dims(x, axis=-1-len(x.shape))?

ke1337 avatar Feb 23 '18 21:02 ke1337

That would work, since I guess you can always ensure that you know the tensor shape. The syntax might be slightly cumbersome, but that's a minor thing.

Thank you for the help.

jsundh avatar Feb 27 '18 09:02 jsundh

The solution is to use C.expand_dims(x, axis=C.Axis.new_leading_axis())

delzac avatar Nov 05 '19 06:11 delzac