Could someone please tell me what this means.

``````a[ ..., j ]
``````

Thank you

3
Contributors
10
Replies
11
Views
5 Years
Discussion Span
Last Post by zeusprog
Featured Replies
• 1

If `a` is an n-dimensional numpy array `a[..., j]` will return an (n-1)-dimensional numpy array where each innermost subarray is replaced by its jth element. So for example if `a` is 2-dimensional, `a[..., j]` will be a 1-dimensional array containing the `j`th column of each row. > Nothing in Python, …

• 1

I'm not sure I understand your question. The values for j and k will not affect the size of the resulting arrays. If `a` is an array of size `n*m` then `a[ ..., j ]` is an array of size `n`, no matter what the value of `j` is. Or …

• 1

The pearsonr function returns a tuple containing two values. The [0] selects the first of those two values.

Nothing in Python, looks like pseudo code.

This is the actual code.

``````for j in range( 0, 10 ) :
for k in range( 0, 10 ) :
r[ j, k ] = scipy.stats.pearsonr( a[ ..., j ], b[ ..., k ] )[ 0 ]
``````

My confusion is that scipy.stats.pearsonr(x, y) accepts 1D arrays for both x and y. But I don't know exactly what the "..." does.

If `a` is an n-dimensional numpy array `a[..., j]` will return an (n-1)-dimensional numpy array where each innermost subarray is replaced by its jth element. So for example if `a` is 2-dimensional, `a[..., j]` will be a 1-dimensional array containing the `j`th column of each row.

Nothing in Python, looks like pseudo code.

Actually, `...` is perfectly valid Python syntax - it's just not used anywhere except by numpy and scipy.

I could kiss you right now #noHomo

Thanks a million

Sorry I have one more question; scipy.stats.pearsonr(x, y) accepts 1D arrays both of the same length. Given varing ranges for j and k, how would this affect the size of the arrays. Thank you

``````for j in range( 0, 30 ) :
for k in range( 0, 10 ) :
r[ j, k ] = scipy.stats.pearsonr( a[ ..., j ], b[ ..., k ] )[ 0 ]
``````

I'm not sure I understand your question. The values for j and k will not affect the size of the resulting arrays. If `a` is an array of size `n*m` then `a[ ..., j ]` is an array of size `n`, no matter what the value of `j` is.

Or more generally: `a[ ..., j ].shape == a.shape[ : -1 ]` for all multi-dimensional arrays `a` and all valid indices `j`.

Thanks again. I've gottten it

Please yet another question. What is the [0] for

``````for j in range( 0, 30 ) :
for k in range( 0, 10 ) :
r[ j, k ] = scipy.stats.pearsonr( a[ ..., j ], b[ ..., k ] )[ 0 ]
``````

The pearsonr function returns a tuple containing two values. The [0] selects the first of those two values.

Thank you