[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

syntax for ellipsis like as "net.blobs['data'].data[...] = transformed_image"

Thanks too,
I have find the answer from "";

This came up in another question recently. I'll elaborate on my answer from there:

Ellipsis is an object that can appear in slice notation. For example:

myList[1:2, ..., 0]

Its interpretation is purely up to whatever implements the __getitem__ function and sees Ellipsis objects there, but its main (and intended) use is in the numeric python extension, which adds a multidimensional array type. Since there are more than one dimensions, slicing becomes more complex than just a start and stop index; it is useful to be able to slice in multiple dimensions as well. E.g., given a 4x4 array, the top left area would be defined by the slice [:2,:2]:

>>> a
array([[ 1,  2,  3,  4],
       [ 5,  6,  7,  8],
       [ 9, 10, 11, 12],
       [13, 14, 15, 16]])

>>> a[:2,:2]  # top left
array([[1, 2],
       [5, 6]])

Extending this further, Ellipsis is used here to indicate a placeholder for the rest of the array dimensions not specified. Think of it as indicating the full slice [:] for all the dimensions in the gap it is placed, so for a 3d array, a[...,0] is the same as a[:,:,0] and for 4d, a[:,:,:,0], similarly, a[0,...,0] is a[0,:,:,0] (with however many colons in the middle make up the full number of dimensions in the array).

Interestingly, in python3, the Ellipsis literal (...) is usable outside the slice syntax, so you can actually write:

>>> ...

Other than the various numeric types, no, I don't think it's used. As far as I'm aware, it was added purely for numpy use and has no core support other than providing the object and corresponding syntax. The object being there didn't require this, but the literal "..." support for slices did.

? 2019-10-26 22:51:31?"xuanwu348" <xuanwu348 at> ???

Hi buddies

Have a good weekend!
I have read some code in caffe, but I confused at "net.blobs['data'].data[...] = transformed_image".
The code can be find in this link:
import caffe
model_def = os.path.join(caffe_root, "models/bvlc_alexnet/deploy.prototxt")
model_weights = os.path.join(caffe_root, "models/bvlc_alexnet/bvlc_alexnet.caffemodel")
net = caffe.Net(model_def,
net.blobs['data'].data[...] = transformed_image

1. For ellipsis, is there syntax in python like this " net.blobs['data'].data[...]"? I have checked it which the type is "<class 'numpy.ndarray'>"
2. Could you provide some samples in which need to use ellipsis. 

But in python, ellipsis define as below, I did not find the relationship to "net.blobs['data'].data[...]":
Help on ellipsis object:

class ellipsis(object)
 |  Methods defined here:
 |  __getattribute__(self, name, /)
 |      Return getattr(self, name).
 |  __new__(*args, **kwargs) from builtins.type
 |      Create and return a new object.  See help(type) for accurate signature.
 |  __reduce__(...)
 |      helper for pickle
 |  __repr__(self, /)
 |      Return repr(self).

Thanks for your help!

Best Regards