3
Contributors
10
Replies
11
Views
4 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, … Read More

  • 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 … Read More

  • 1

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

0

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.

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 jth 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.

0

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 ]
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 more generally: a[ ..., j ].shape == a.shape[ : -1 ] for all multi-dimensional arrays a and all valid indices j.

0

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 ]
1

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.