网站应该怎么做,做网站有高手没有,做百度推广和企业网站那个有效果吗,做网站需要服务器我最近一直致力于一个项目,其中我的大部分时间花费在密集矩阵A和稀疏向量v上(见here).在我尝试减少计算时,我注意到A.dot(v)的运行时间不受v的零条目数的影响.为了解释为什么我希望在这种情况下改进运行时,让result A.dot.v使得j 1的结果[j] sum_i(A [i,j] * v [j])… v.sha…我最近一直致力于一个项目,其中我的大部分时间花费在密集矩阵A和稀疏向量v上(见here).在我尝试减少计算时,我注意到A.dot(v)的运行时间不受v的零条目数的影响.为了解释为什么我希望在这种情况下改进运行时,让result A.dot.v使得j 1的结果[j] sum_i(A [i,j] * v [j])… v.shape [0].如果v [j] 0,则无论值A [::,j]如何,显然结果[j] 0.在这种情况下,我希望numpy只设置result [j] 0,但似乎它继续并计算sum_i(A [i,j] * v [j])无论如何.我继续编写了一个简短的示例脚本来确认下面的这种行为.import timeimport numpy as npnp.__config__.show() #make sure BLAS/LAPACK is being usednp.random.seed(seed 0)n_rows, n_cols 1e5, 1e3#initialize matrix and vectorA np.random.rand(n_rows, n_cols)u np.random.rand(n_cols)u np.require(u, dtypeA.dtype, requirements [C])#timestart_time time.time()A.dot(u)print time with %d non-zero entries: %1.5f seconds % (sum(u0.0), (time.time() - start_time))#set all but one entry of u to zerov uset_to_zero np.random.choice(np.array(range(0, u.shape[0])), size (u.shape[0]-2), replaceFalse)v[set_to_zero] 0.0start_time time.time()A.dot(v)print time with %d non-zero entries: %1.5f seconds % (sum(v0.0), (time.time() - start_time))#what I would really expect it to takenon_zero_index np.squeeze(v ! 0.0)A_effective A[::,non_zero_index]v_effective v[non_zero_index]start_time time.time()A_effective.dot(v_effective)print expected time with %d non-zero entries: %1.5f seconds % (sum(v0.0), (time.time() - start_time))运行这个,我得到矩阵向量乘法的运行时是相同的,无论我使用密集矩阵u还是稀疏矩阵vtime with 0 non-zero entries: 0.04279 secondstime with 999 non-zero entries: 0.04050 secondsexpected time with 999 non-zero entries: 0.00466 seconds我想知道这是否是设计的或者我错过了我正在运行矩阵向量乘法的方式.就像健全性检查一样我确保numpy链接到我的机器上的BLAS库,并且两个数组都是C_CONTIGUOUS(因为这显然需要numpy来调用BLAS).