From f60fcc2bc829a64a9c2751e7731f270640648331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=80=E5=A7=8B=E8=AF=B4=E6=95=85=E4=BA=8B?= <7985556+fzgandw@user.noreply.gitee.com> Date: Wed, 14 Oct 2020 11:42:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20core=20=E7=9A=84=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E6=A8=A1=E5=9D=97=20=E4=BC=98=E5=8C=96size?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E7=9A=84=E4=BD=BF=E7=94=A8=20=EF=BC=881?= =?UTF-8?q?=EF=BC=89=E6=95=B0=E6=8D=AE=E7=B1=BB=E5=9E=8B=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=EF=BC=8C=E5=8C=85=E6=8B=AC=20numpy.arrary=EF=BC=8Cpandas.DataF?= =?UTF-8?q?rame=EF=BC=8Csympy.Matrix=EF=BC=8Clist=EF=BC=8Ctuple=EF=BC=8Cdi?= =?UTF-8?q?ct=E7=AD=89=20=EF=BC=882=EF=BC=89=E4=BF=AE=E5=A4=8D=E4=BA=86BUG?= =?UTF-8?q?=EF=BC=8C=E5=8E=9F=E5=A7=8B=E4=BB=A3=E7=A0=81=E4=B8=AD=EF=BC=8C?= =?UTF-8?q?=E5=A6=82=E6=9E=9Csize=E9=92=88=E5=AF=B9=E7=9A=84=E6=98=AF?= =?UTF-8?q?=E5=85=B6=E4=BB=96=E7=89=B9=E6=AE=8A=E6=95=B0=E6=8D=AE=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=EF=BC=8C=E8=BF=94=E5=9B=9E=E7=BB=93=E6=9E=9C=E4=B8=BA?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=EF=BC=8C=E5=9C=A8=E5=AE=9E=E9=99=85?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E4=B8=AD=E5=8F=AF=E8=83=BD=E4=BC=9A=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E4=B8=8B=E6=B8=B8=E5=87=BA=E7=8E=B0=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E9=A2=84=E4=BC=B0=E7=9A=84=E9=94=99=E8=AF=AF=EF=BC=8C=E7=9B=AE?= =?UTF-8?q?=E5=89=8D=E9=81=87=E5=88=B0=E7=89=B9=E6=AE=8A=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E6=97=A0=E6=B3=95=E8=A7=A3=E6=9E=90=E6=97=B6?= =?UTF-8?q?=E5=88=99=E6=8A=A5=E9=94=99=E8=BF=94=E5=9B=9ETypeError=E6=8F=90?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/__init__.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/core/__init__.py b/core/__init__.py index 7f281279..19991f0a 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) -- Gitee