我正在尝试对两个大型稀疏矩阵进行元素乘法。两者的大小都在 (400K X 500K) 左右,大约有 100M 元素。
但是,它们可能不会在相同位置具有非零元素,并且它们可能不会具有相同数量的非零元素。在任何一种情况下,我都可以将一个矩阵的非零值和另一个矩阵中的零值相乘为零。
我在每种方法中都不断耗尽内存(8GB),这没有多大意义。我不应该。这些是我尝试过的。
A 和 B 是稀疏矩阵(我尝试过 COO 和 CSC 格式)。
# I have loaded sparse matrices A and B, and have a file opened in write mode
row,col = A.nonzero()
index = zip(row,col)
del row,col
for i,j in index :
# Approach 1
A[i,j] *= B[i,j]
# Approach 2
someopenfile.write(' '.join([str(i),str(j),str(A[j,j]*B[i,j]),'\n']))
# Approach 3
if B[i,j] != 0 :
A[i,j] = A[i,j]*B[i,j] # or, I wrote it to a file instead
# like …Run Code Online (Sandbox Code Playgroud) 我试图使用两个线程从python程序调用Octave函数.我的八度代码只是为了看它是如何工作的 -
testOctave.m
function y = testOctave(i)
y = i;
end
Run Code Online (Sandbox Code Playgroud)
而python程序只是试图调用它
from oct2py import octave
import thread
def func(threadName,i) :
print "hello",threadName // This printf works
y = octave.testOctave(i)
print y // This is ignored
print 'done' // This is ignored
print 'exiting' // This is ignored
try:
thread.start_new_thread( func, ("Thread-1", 100 ) )
thread.start_new_thread( func, ("Thread-2", 150 ) )
except:
print "Error: unable to start thread"
Run Code Online (Sandbox Code Playgroud)
程序退出时不会出现任何错误,但在上面的函数中,只执行第一次打印,两个线程都会忽略八度调用之后的所有打印.是否有这种情况发生的原因,我该怎么做才能使它发挥作用?
该程序没有做任何特别的事情,我只想弄清楚如何使用oct2py