Python Forum
how is Ellipsis or ... used?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how is Ellipsis or ... used?
#1
how is Ellipsis or ... used in Python code? has anyone here had a need to use it? has anyone here ever seen it used in code not in a comment?

...
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
It is used in rumpy array slicing and also in the typing module. However it was added to Python because some folks thought that it would be cute to be able to write
def spam(): ...
and Guido agreed
Reply
#3
(Oct-01-2022, 07:24 PM)Gribouillis Wrote: rumpy
rumpy?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
it was just a typo it's numpy
Reply
#5
this one is the use case that looks cute to me.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#6
Useful for numpy if you have a multidimensional array and want to have a placeholder to address a range of dimensions. The ... consume as many elements, as dimensions left. The comma in the brackets addresses the next dimension.

import numpy as np


radar_data = np.ones([3, 256, 256, 2])
# 3 Sensors, 256 chirps, fft 256 values, i and q data
radar_iq = 1j * radar_data[..., 0] + radar_data[..., 1]
# 3 Sensors, 256 chirps, fft 256 values complex 128
The use for typhints came afterwards.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#7
and numpy is the (initially only) implementation recognizing ... (e.g. nothing in the interpreter does so other than seeing that it is a different type than expected)?

can i use ... for something else (not saying what for) that does not involve numpy?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#8
(Oct-03-2022, 10:25 PM)Skaperen Wrote: can i use ... for something else
Of course, use it for something else. Python is excellent for experimenting things.
Reply
#9
(Oct-03-2022, 10:25 PM)Skaperen Wrote: can i use ... for something else (not saying what for)

Yes. For example, you can use this object as a sentinel. The ... which is Ellipsis is a singleton like True, False and None. So, they exist only once per process. The difference to None is, that bool(Ellipsis) returns True.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#10
so i should compare with "is" like i do for True, False, None.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Ellipsis Skaperen 3 2,372 May-20-2019, 10:46 AM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020