import numpy as np import scipy.sparse as sp m = sp.lil_matrix((7329,7329)) np.save(path,m) #用numpy的load方法存储矩阵,path为存储的路径 mat = np.load(path)[()] #读取存储的矩阵,注意[()]这个符号可以抽取对象 mat = mat.toarray() #将稀疏矩阵转为稠密矩阵
OpenCV中Mat矩阵data数据的存储方式和二维数组不一致,二维数组按照行优先的顺序依次存储,而Mat中还有一个标示行步进的变量Step.使用Mat.ptr<DataTyte>(row) 行指针的方式定位到每一行,可快速遍历矩阵.例程如下: std::cout << "The inverse matrix of K is:" << std::endl; ;i<;i++) { float* data = mInvK.ptr<float&
>> A = [ ; ; ] A = 1. 选择第m行n列的元素 >> A(,) ans = 2. 选择第i列所有元素 >> A(:,) ans = 3. 选择第j行所有元素 >> A(,:) ans = 4. 选择从第i列到第j列的所有元素 >> A(:,:) ans = >> A(:,:) ans = 5. 删除矩阵里面的行 >> A(,:)=[] A = 6. 复制矩阵里面的行创建新矩阵 >> E = A
我觉得我的算法比较简单易懂,比网上的那些简单些.至于时间复杂度就没有比较了. 算法思想:从最外层向内层遍历矩阵 # my algorithmimport math def print_matrix(matrix): rec = [] # 存储遍历元素 rows = len(matrix) cols = len(matrix[0]) if rows < cols: k = math.ceil(rows/2) else: k = math.ceil(cols/2) for n in range(k)