covariance

Numpy Covariance Matrix numpy.cov

左心房为你撑大大i 提交于 2020-08-18 07:48:14
问题 I am using numpy and want to compute the covariance matrix for an ndarray. I am trying to use numpy.cov() but am not getting the correct results. More details below. My ndarray is 768x8 for where 8 is the numbers features in my data set. When I use MATLAB to compute the covariance matrix, I get a 8x8 (which is what I require), but when I use np.cov(), I get a 768x768 which is incorrect. I tried changing the rowvar argument to true and this does not work. What would be the correct call to

How to model a covariant association-class in UML?

╄→гoц情女王★ 提交于 2020-07-22 10:59:20
问题 In short I would like to model a covariant association between two classes, that can each be specialized. I need to show the specialization of the related association-classes. But I want to avoid that my model could mean that there are redundant associations (i.e. one between the generalizations and one between the specializations. Step by step explanation of the problem I have in an UML class diagram a many-many association between a Person and a Contract . A person can be involved in

Can you specify variance in a Python type annotation?

怎甘沉沦 提交于 2020-06-16 07:07:46
问题 Can you spot the error in the code below? Mypy can't. from typing import Dict, Any def add_items(d: Dict[str, Any]) -> None: d['foo'] = 5 d: Dict[str, str] = {} add_items(d) for key, value in d.items(): print(f"{repr(key)}: {repr(value.lower())}") Python spots the error, of course, helpfully informing us that 'int' object has no attribute 'lower' . Too bad it can't tell us this until run time. As far as I can tell, mypy doesn't catch this error because it allows arguments to the d parameter

Can you specify variance in a Python type annotation?

a 夏天 提交于 2020-06-16 07:07:18
问题 Can you spot the error in the code below? Mypy can't. from typing import Dict, Any def add_items(d: Dict[str, Any]) -> None: d['foo'] = 5 d: Dict[str, str] = {} add_items(d) for key, value in d.items(): print(f"{repr(key)}: {repr(value.lower())}") Python spots the error, of course, helpfully informing us that 'int' object has no attribute 'lower' . Too bad it can't tell us this until run time. As far as I can tell, mypy doesn't catch this error because it allows arguments to the d parameter

How does Optional covariance work in Swift

荒凉一梦 提交于 2020-06-10 02:43:22
问题 How does covariance work for Optional s in Swift? Say I write the following code: var nativeOptionalView: Optional<UIView> let button = UIButton() nativeOptionalView = .Some(button) var nativeOptionalButton = Optional.Some(button) nativeOptionalView = nativeOptionalButton It compiles and works just fine. However if I define MyOptional as enum MyOptional<T> { case Some(T) case None } And write the following: var myOptionalView: MyOptional<UIView> let button = UIButton() myOptionalView = .Some

How does Optional covariance work in Swift

邮差的信 提交于 2020-06-10 02:43:20
问题 How does covariance work for Optional s in Swift? Say I write the following code: var nativeOptionalView: Optional<UIView> let button = UIButton() nativeOptionalView = .Some(button) var nativeOptionalButton = Optional.Some(button) nativeOptionalView = nativeOptionalButton It compiles and works just fine. However if I define MyOptional as enum MyOptional<T> { case Some(T) case None } And write the following: var myOptionalView: MyOptional<UIView> let button = UIButton() myOptionalView = .Some

Vectorizing NumPy covariance for 3D array

最后都变了- 提交于 2020-06-06 08:12:08
问题 I have a 3D numpy array of shape (t, n1, n2) : x = np.random.rand(10, 2, 4) I need to calculate another 3D array y which is of shape (t, n1, n1) such that: y[0] = np.cov(x[0,:,:]) ...and so on for all slices along the first axis. So, a loopy implementation would be: y = np.zeros((10,2,2)) for i in np.arange(x.shape[0]): y[i] = np.cov(x[i, :, :]) Is there any way to vectorize this so I can calculate all covariance matrices in one go? I tried doing: x1 = x.swapaxes(1, 2) y = np.dot(x, x1) But

In Haxe, can you write a generic interface where a method type parameter is constrained by the class's type parameter?

♀尐吖头ヾ 提交于 2020-05-30 03:54:29
问题 I'm having trouble writing the generic interface below. In my class, I have a function that takes an array of < any type that extends a parent class > and traces its first element. Since I'm only reading elements from the array, I'm using it as if its a covariant compound type, and therefore I'm guaranteed to have the cast statement never fail. Now I want to abstract this out even more and write a interface that defines fn using another generic type T. I want fn to be able to accept any Array

In Haxe, can you write a generic interface where a method type parameter is constrained by the class's type parameter?

♀尐吖头ヾ 提交于 2020-05-30 03:53:12
问题 I'm having trouble writing the generic interface below. In my class, I have a function that takes an array of < any type that extends a parent class > and traces its first element. Since I'm only reading elements from the array, I'm using it as if its a covariant compound type, and therefore I'm guaranteed to have the cast statement never fail. Now I want to abstract this out even more and write a interface that defines fn using another generic type T. I want fn to be able to accept any Array

Diagonal element for covariance matrix not 1 pandas/numpy

萝らか妹 提交于 2020-05-26 06:34:50
问题 I have the following dataframe: A B 0 1 5 1 2 6 2 3 7 3 4 8 I wish to calculate the covariance a = df.iloc[:,0].values b = df.iloc[:,1].values Using numpy for cov as : numpy.cov(a,b) I get: array([[ 1.66666667, 1.66666667], [ 1.66666667, 1.66666667]]) Shouldn't the diagonal elements be 1? How do I get the diagonal elements to 1? 回答1: No they shouldn't. I think you might be confusing it with Correlation. Correlation and Covariance are different. What you see in the diagonals is simply the