diff --git a/core/__init__.py b/core/__init__.py index 7f281279d8a0c35355974ca258e4d40e70ce1e3b..19991f0af8933d29935a6a601cc7e1dcedf3153f 100644 --- a/core/__init__.py +++ b/core/__init__.py @@ -1,6 +1,7 @@ import matplotlib.pyplot as plt -import numpy as np -import pandas as pd +import numpy +import pandas +import sympy # 导入基本数学变量和函数 from math import ( @@ -146,18 +147,24 @@ def version(): print("1.0.1") -def size(x) -> np.array: +def size(x): """ 获取矩阵的行数和列数 参数 ---------- - x : np.array + x : numpy.ndarray, pandas.DataFrame, sympy.Matrix + + 注意 + ---------- + (1)返回长度时,仅针对最外层,不做深度统计 """ - if type(x) is np.ndarray: - return x.shape - else: - try: - return np.array(x).shape - except: - return "data type is not support" + sizeFunc = [ + numpy.ndarray, pandas.DataFrame, sympy.Matrix + ] + try: + res = len(x) if type(x) not in sizeFunc else x.shape + return(res) + except: + e = str(type(x)).split("'")[1] + raise TypeError("'{}' object does not support checking size!".format(e)