@@ -2268,13 +2268,13 @@ def _vectorize_call_with_signature(self, func, args):
2268
2268
2269
2269
2270
2270
def _cov_dispatcher (m , y = None , rowvar = None , bias = None , ddof = None ,
2271
- fweights = None , aweights = None ):
2271
+ fweights = None , aweights = None , * , dtype = None ):
2272
2272
return (m , y , fweights , aweights )
2273
2273
2274
2274
2275
2275
@array_function_dispatch (_cov_dispatcher )
2276
2276
def cov (m , y = None , rowvar = True , bias = False , ddof = None , fweights = None ,
2277
- aweights = None ):
2277
+ aweights = None , * , dtype = None ):
2278
2278
"""
2279
2279
Estimate a covariance matrix, given data and weights.
2280
2280
@@ -2325,6 +2325,11 @@ def cov(m, y=None, rowvar=True, bias=False, ddof=None, fweights=None,
2325
2325
weights can be used to assign probabilities to observation vectors.
2326
2326
2327
2327
.. versionadded:: 1.10
2328
+ dtype : data-type, optional
2329
+ Data-type of the result. By default, the return data-type will have
2330
+ at least `numpy.float64` precision.
2331
+
2332
+ .. versionadded:: 1.20
2328
2333
2329
2334
Returns
2330
2335
-------
@@ -2400,13 +2405,16 @@ def cov(m, y=None, rowvar=True, bias=False, ddof=None, fweights=None,
2400
2405
if m .ndim > 2 :
2401
2406
raise ValueError ("m has more than 2 dimensions" )
2402
2407
2403
- if y is None :
2404
- dtype = np .result_type (m , np .float64 )
2405
- else :
2408
+ if y is not None :
2406
2409
y = np .asarray (y )
2407
2410
if y .ndim > 2 :
2408
2411
raise ValueError ("y has more than 2 dimensions" )
2409
- dtype = np .result_type (m , y , np .float64 )
2412
+
2413
+ if dtype is None :
2414
+ if y is None :
2415
+ dtype = np .result_type (m , np .float64 )
2416
+ else :
2417
+ dtype = np .result_type (m , y , np .float64 )
2410
2418
2411
2419
X = array (m , ndmin = 2 , dtype = dtype )
2412
2420
if not rowvar and X .shape [0 ] != 1 :
@@ -2486,12 +2494,14 @@ def cov(m, y=None, rowvar=True, bias=False, ddof=None, fweights=None,
2486
2494
return c .squeeze ()
2487
2495
2488
2496
2489
- def _corrcoef_dispatcher (x , y = None , rowvar = None , bias = None , ddof = None ):
2497
+ def _corrcoef_dispatcher (x , y = None , rowvar = None , bias = None , ddof = None , * ,
2498
+ dtype = None ):
2490
2499
return (x , y )
2491
2500
2492
2501
2493
2502
@array_function_dispatch (_corrcoef_dispatcher )
2494
- def corrcoef (x , y = None , rowvar = True , bias = np ._NoValue , ddof = np ._NoValue ):
2503
+ def corrcoef (x , y = None , rowvar = True , bias = np ._NoValue , ddof = np ._NoValue , * ,
2504
+ dtype = None ):
2495
2505
"""
2496
2506
Return Pearson product-moment correlation coefficients.
2497
2507
@@ -2525,6 +2535,11 @@ def corrcoef(x, y=None, rowvar=True, bias=np._NoValue, ddof=np._NoValue):
2525
2535
Has no effect, do not use.
2526
2536
2527
2537
.. deprecated:: 1.10.0
2538
+ dtype : data-type, optional
2539
+ Data-type of the result. By default, the return data-type will have
2540
+ at least `numpy.float64` precision.
2541
+
2542
+ .. versionadded:: 1.20
2528
2543
2529
2544
Returns
2530
2545
-------
@@ -2616,7 +2631,7 @@ def corrcoef(x, y=None, rowvar=True, bias=np._NoValue, ddof=np._NoValue):
2616
2631
# 2015-03-15, 1.10
2617
2632
warnings .warn ('bias and ddof have no effect and are deprecated' ,
2618
2633
DeprecationWarning , stacklevel = 3 )
2619
- c = cov (x , y , rowvar )
2634
+ c = cov (x , y , rowvar , dtype = dtype )
2620
2635
try :
2621
2636
d = diag (c )
2622
2637
except ValueError :
0 commit comments