本文整理汇总了Python中scipy.sparse.sputils.isdense方法的典型用法代码示例。如果您正苦于以下问题:Python sputils.isdense方法的具体用法?Python sputils.isdense怎么用?Python sputils.isdense使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.sparse.sputils
的用法示例。
在下文中一共展示了sputils.isdense方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: f1_per_sample
# 需要导入模块: from scipy.sparse import sputils [as 别名]
# 或者: from scipy.sparse.sputils import isdense [as 别名]
def f1_per_sample(y_true, y_pred):
if isdense(y_true) or isdense(y_pred):
y_true = sp.csr_matrix(y_true)
y_pred = sp.csr_matrix(y_pred)
sum_axis = 1
true_and_pred = y_true.multiply(y_pred)
tp_sum = count_nonzero(true_and_pred, axis=sum_axis)
pred_sum = count_nonzero(y_pred, axis=sum_axis)
true_sum = count_nonzero(y_true, axis=sum_axis)
with np.errstate(divide='ignore', invalid='ignore'):
precision = _prf_divide(tp_sum, pred_sum)
recall = _prf_divide(tp_sum, true_sum)
f_score = (2 * precision * recall / (1 * precision + recall))
f_score[tp_sum == 0] = 0.0
return f_score
示例2: get_inv_matvec
# 需要导入模块: from scipy.sparse import sputils [as 别名]
# 或者: from scipy.sparse.sputils import isdense [as 别名]
def get_inv_matvec(M, symmetric=False, tol=0):
if isdense(M):
return LuInv(M).matvec
elif isspmatrix(M):
if isspmatrix_csr(M) and symmetric:
M = M.T
return SpLuInv(M).matvec
else:
return IterInv(M, tol=tol).matvec
示例3: get_OPinv_matvec
# 需要导入模块: from scipy.sparse import sputils [as 别名]
# 或者: from scipy.sparse.sputils import isdense [as 别名]
def get_OPinv_matvec(A, M, sigma, symmetric=False, tol=0):
if sigma == 0:
return get_inv_matvec(A, symmetric=symmetric, tol=tol)
if M is None:
#M is the identity matrix
if isdense(A):
if (np.issubdtype(A.dtype, np.complexfloating)
or np.imag(sigma) == 0):
A = np.copy(A)
else:
A = A + 0j
A.flat[::A.shape[1] + 1] -= sigma
return LuInv(A).matvec
elif isspmatrix(A):
A = A - sigma * eye(A.shape[0])
if symmetric and isspmatrix_csr(A):
A = A.T
return SpLuInv(A.tocsc()).matvec
else:
return IterOpInv(_aslinearoperator_with_dtype(A),
M, sigma, tol=tol).matvec
else:
if ((not isdense(A) and not isspmatrix(A)) or
(not isdense(M) and not isspmatrix(M))):
return IterOpInv(_aslinearoperator_with_dtype(A),
_aslinearoperator_with_dtype(M),
sigma, tol=tol).matvec
elif isdense(A) or isdense(M):
return LuInv(A - sigma * M).matvec
else:
OP = A - sigma * M
if symmetric and isspmatrix_csr(OP):
OP = OP.T
return SpLuInv(OP.tocsc()).matvec
# ARPACK is not threadsafe or reentrant (SAVE variables), so we need a
# lock and a re-entering check.
示例4: test_isdense
# 需要导入模块: from scipy.sparse import sputils [as 别名]
# 或者: from scipy.sparse.sputils import isdense [as 别名]
def test_isdense(self):
assert_equal(sputils.isdense(np.array([1])),True)
assert_equal(sputils.isdense(np.matrix([1])),True)
示例5: get_OPinv_matvec
# 需要导入模块: from scipy.sparse import sputils [as 别名]
# 或者: from scipy.sparse.sputils import isdense [as 别名]
def get_OPinv_matvec(A, M, sigma, symmetric=False, tol=0):
if sigma == 0:
return get_inv_matvec(A, symmetric=symmetric, tol=tol)
if M is None:
#M is the identity matrix
if isdense(A):
if (np.issubdtype(A.dtype, np.complexfloating)
or np.imag(sigma) == 0):
A = np.copy(A)
else:
A = A + 0j
A.flat[::A.shape[1] + 1] -= sigma
return LuInv(A).matvec
elif isspmatrix(A):
A = A - sigma * eye(A.shape[0])
if symmetric and isspmatrix_csr(A):
A = A.T
return SpLuInv(A.tocsc()).matvec
else:
return IterOpInv(_aslinearoperator_with_dtype(A),
M, sigma, tol=tol).matvec
else:
if ((not isdense(A) and not isspmatrix(A)) or
(not isdense(M) and not isspmatrix(M))):
return IterOpInv(_aslinearoperator_with_dtype(A),
_aslinearoperator_with_dtype(M),
sigma, tol=tol).matvec
elif isdense(A) or isdense(M):
return LuInv(A - sigma * M).matvec
else:
OP = A - sigma * M
if symmetric and isspmatrix_csr(OP):
OP = OP.T
return SpLuInv(OP.tocsc()).matvec
示例6: test_isdense
# 需要导入模块: from scipy.sparse import sputils [as 别名]
# 或者: from scipy.sparse.sputils import isdense [as 别名]
def test_isdense(self):
assert_equal(sputils.isdense(np.array([1])), True)
assert_equal(sputils.isdense(np.matrix([1])), True)