/// <summary> /// 执行Get操作 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="target"></param> /// <returns></returns> protected Result <T> Wrap <T>(WrapDelegate <T> target) { var result = new Result <T>(); try { T entity = target(); result.Code = null == entity ? ResultCode.Error : ResultCode.Success; result.Message = result.Code == ResultCode.Success ? "" : "操作失败"; result.Data = entity; } catch (Exception ex) { result.Code = ResultCode.Error; result.Message = "系统异常!" + ex.Message; } return(result); }
/// <summary> /// Create a two-dimensional array with the flattened input as a diagonal. /// </summary> /// <param name="v">Input data</param> /// <param name="k">Diagonal to set; 0, the default, corresponds to the "main" diagonal, a positive(negative) `k` giving the number of the diagonal above (below) the main.</param> /// <returns></returns> public static ndarray diagflat(ndarray v, int k = 0) { /* * Create a two-dimensional array with the flattened input as a diagonal. * * Parameters * ---------- * v : array_like * Input data, which is flattened and set as the `k`-th * diagonal of the output. * k : int, optional * Diagonal to set; 0, the default, corresponds to the "main" diagonal, * a positive (negative) `k` giving the number of the diagonal above * (below) the main. * * Returns * ------- * out : ndarray * The 2-D output array. * * See Also * -------- * diag : MATLAB work-alike for 1-D and 2-D arrays. * diagonal : Return specified diagonals. * trace : Sum along diagonals. * * Examples * -------- * >>> np.diagflat([[1,2], [3,4]]) * array([[1, 0, 0, 0], * [0, 2, 0, 0], * [0, 0, 3, 0], * [0, 0, 0, 4]]) * * >>> np.diagflat([1,2], 1) * array([[0, 1, 0], * [0, 0, 2], * [0, 0, 0]]) */ ndarray fi; WrapDelegate wrap = null; v = asarray(v).ravel(); int s = len(v); int n = s + Math.Abs(k); ndarray res = zeros(new shape(n, n), dtype: v.Dtype); if (k >= 0) { ndarray i = arange(0, n - k, null, null); fi = i + k + i * n; } else { ndarray i = arange(0, n + k, null, null); fi = i + (i - k) * n; } res.Flat[fi] = v; if (wrap == null) { return(res); } return(wrap(res)); }