I don't know if you've ever seen the use of the... symbol in python arrays. symbol, because some time ago when reading other people's code encountered this symbol immediately cloudy, so here is a record. First, let's look at a piece of code:
import numpy as np x = ([[1, 3], [5, 6], [8, 10]]) print("Using the '...' symbol results in the following:") print(x[..., 0]) print("The result of using the ':' symbol is:") print(x[:, 0]) """ Using the '...' symbol results in: [1 5 8] The result of using the ':' notation is: [1 5 8] """
It is not difficult to compare the results and conclude that in python arrays, ... s are functionally equivalent to :symbols. However is this really the case? The answer is no. Let's look at the case of 3D arrays again.
import numpy as np x = ([[[0, 1], [2, 3]], [[4, 5], [5, 6]], [[7, 8], [9, 10]]]) print("Using the '...' symbol results in the following:") print(x[..., 0]) print("The result of using two ':' symbols is:") print(x[:, :, 1]) print("The result of using a ':' symbol is:") print(x[:, 1]) """ Using the '...' symbol results in: [[0 2] [4 5] [7 9]] The result of using two ':' symbols is: [[ 1 3] [ 5 6] [ 8 10]] The result of using one ':' symbol is: [[ 2 3] [ 5 6] [ 9 10]] """
We can see that using the symbol ... is consistent with the result of using two : symbols, but differs from the result of using a single : symbol. So we can get that the symbol ... is not exactly equivalent to the symbol :.
Conclusion: For two-dimensional arrays, the symbol ... is equivalent to the symbol :, but not for three-dimensional arrays, considering the specific case.
To this point this article on the python array symbols in detail... With: the difference between the symbols of the article is introduced to this, more related python array symbols content please search my previous posts or continue to browse the following related articles I hope you will support me more in the future!