[英]Convert Numpy matrix values to be float32
I want to enforce the values in the eigenvector matrix below to be of type float32
to save memory space instead of using float64
. 我想将下面的特征向量矩阵中的值强制为
float32
类型,以节省内存空间,而不是使用float64
。 However, it seems the way I did below eigenvectors.astype(np.float32)
does not work. 但是,似乎我在
eigenvectors.astype(np.float32)
执行的方法不起作用。 Is there a work around of that? 有没有解决的办法?
import networkx as nx
G = nx.Graph(edges)
L = nx.laplacian_matrix(G)
eigenvalues, eigenvectors.astype(np.float32) = np.linalg.eig(L.todense())
The np.linalg.eig
function returns arrays of the same dtype
as its parameter. 所述
np.linalg.eig
函数返回相同的阵列dtype
作为其参数。
So you have two choices: 因此,您有两种选择:
np.linalg.eig(L.todense().astype(np.float32))
. np.linalg.eig(L.todense().astype(np.float32))
。 (This might overflow) The second option goes like this: 第二个选项是这样的:
eigenvalues, eigenvectors = np.linalg.eig(L.todense())
eigenvectors = eigenvectors.astype(np.float32)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.