Linked Questions

0 votes
1 answer
93 views

What the meaning of `text[..., :5]` in python? [duplicate]

I am confused about one code line in Github, in line 295 text = text[..., :5] I was wondering if it take the text list from index=0 to 5. However, it didn't work, I tried to use text = ["an oil ...
4daJKong's user avatar
  • 1,977
0 votes
0 answers
28 views

Adding a new dimension to a Numpy array [duplicate]

I'm newbie with Python. I have found this code: array = FLAIR_array[..., np.newaxis] # FLAIR_array is a Numpy array. FLAIR_array shape is (960, 200, 200) and array shape is (960, 200, 200, 1). np....
VansFannel's user avatar
  • 45.4k
1415 votes
191 answers
726k views

Hidden features of Python [closed]

What are the lesser-known but useful features of the Python programming language? Try to limit answers to Python core. One feature per answer. Give an example and short description of the feature, ...
866 votes
14 answers
305k views

What does the Ellipsis object do?

While idly surfing the namespace I noticed an odd looking object called Ellipsis, it does not seem to be or do anything special, but it's a globally available builtin. After a search I found that it ...
Salim Fadhley's user avatar
13 votes
1 answer
4k views

What does [...] (an ellipsis) in a list mean in Python? [duplicate]

I just got some weird output of a python script: [[(7, 6), (6, 4), (7, 2)], [...], [...], [...], [(7, 6), (8, 4), (7, 2)], [...], [...], [...], [...], [...], [...], [...]] The output should be a ...
Martin Thoma's user avatar
7 votes
4 answers
8k views

python: extracting one slice of a multidimensional array given the dimension index

I know how to take x[:,:,:,:,j,:] (which takes the jth slice of dimension 4). Is there a way to do the same thing if the dimension is known at runtime, and is not a known constant?
Jason S's user avatar
  • 187k
8 votes
4 answers
3k views

Custom placeholder like None in python

I'm using argspec in a function that takes another function or method as the argument, and returns a tuple like this: (("arg1", obj1), ("arg2", obj2), ...) This means that the first argument to the ...
Lauritz V. Thaulow's user avatar
7 votes
3 answers
2k views

What does ... mean in numpy code?

And what is it called? I don't know how to search for it; I tried calling it ellipsis with the Google. I don't mean in interactive output when dots are used to indicate that the full array is not ...
Thomas's user avatar
  • 6,625
10 votes
2 answers
3k views

Mapping element-wise a NumPy array into an array of more dimensions

I want map a numpy.array from NxM to NxMx3, where a vector of three elements is a function of the original entry: lambda x: [f1(x), f2(x), f3(x)] However, things like numpy.vectorize do not allow to ...
Piotr Migdal's user avatar
  • 12.3k
4 votes
1 answer
5k views

What is the use of Ellipsis in Python?

Could someone please help, what is the use of Ellipse in Python with some examples and when to use it? I have done some search on this it can be used with a function : def add(): ... and with ...
Ashish Dhamu's user avatar
0 votes
3 answers
1k views

List of lists TypeError: list indices must be integers or slices, not tuple

Here is my list of lists and I'm trying to print a certain element: boxes_preds = [[1, 300, 400, 250, 350],[0, 450, 150, 500, 420]] print(boxes_preds[..., 0:1]) I get a TypeError: list indices must ...
keeponlearning101's user avatar
3 votes
3 answers
509 views

What's the most efficient way to share large amounts of data between Python and C++

I'm writing a system that allows python scripts to be executed within a C++ application. The python scripts are used to modify values within arrays of data (typically 2048x2048x4 arrays of floats) ...
user avatar
2 votes
1 answer
452 views

How does one index a numpy array using another numpy array that holds the indices?

This should be simple task but I am ashamed to admit I'm stuck. I have a numpy array, called X: X.shape is (10,3)and it looks like [[ 0. 0. 13. ] [ 0. 0. 1. ] [ 0. 4. 16. ] ..., ...
tumultous_rooster's user avatar
0 votes
0 answers
741 views

Difference between arr[..., 0] and arr[:, 0] [duplicate]

What is the difference between the two notations for 'slicing' an array? from numpy import ones arr = ones((3,3)) arr[:, 0] += 1 arr[..., 1] += 2 #arr #array([[2, 3, 1], # [2, 3, 1], # [...
izxle's user avatar
  • 396
2 votes
1 answer
122 views

What does this Slicing and Ellipse index operations result in?

I try to understand what happens with this code using ndarrays: max_evecs = evecs[..., :, 0] where evecs is of type ndarray. So far I know that ':' is a slicing operator, and '...' is a so called ...
math's user avatar
  • 8,652

15 30 50 per page