Tag: numpy

在Python中稀疏的3dmatrix/数组?

在scipy中,我们可以使用scipy.sparse.lil_matrix()等构造一个稀疏matrix,但matrix在2d中。 我想知道在Python中是否有稀疏的3Dmatrix/数组(张量)的现有数据结构? ps我有很多稀疏的3D数据,需要张量来存储/执行乘法。 如果没有现有的数据结构,有什么build议来实现这样一个张量?

如何将2D列表转换为2D numpy数组?

我有一个2D列表的东西 a = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] 我想把它转换成一个2D的numpy数组。 我们能不能像这样分配内存呢? numpy.zeros((3,3)) 然后存储值呢?

为什么numpy.power为小指数返回0,而math.pow返回正确的答案?

In [25]: np.power(10,-100) Out[25]: 0 In [26]: math.pow(10,-100) Out[26]: 1e-100 我希望这两个命令都能返回1e-100。 这也不是一个精确的问题,因为即使将精度提高到500之后问题仍然存在。是否有一些设置可以改变以获得正确答案?

从嵌套列表中创build数组时,禁止在Numpy中使用科学表示法

我有一个嵌套的列表,如下所示: my_list = [[3.74, 5162, 13683628846.64, 12783387559.86, 1.81], [9.55, 116, 189688622.37, 260332262.0, 1.97], [2.2, 768, 6004865.13, 5759960.98, 1.21], [3.74, 4062, 3263822121.39, 3066869087.9, 1.93], [1.91, 474, 44555062.72, 44555062.72, 0.41], [5.8, 5006, 8254968918.1, 7446788272.74, 3.25], [4.5, 7887, 30078971595.46, 27814989471.31, 2.18], [7.03, 116, 66252511.46, 81109291.0, 1.56], [6.52, 116, 47674230.76, 57686991.0, 1.43], [1.85, 623, 3002631.96, 2899484.08, 0.64], [13.76, 1227, […]

使用buildozer将Kivy与numpy库for Android打包时出错

我正在尝试使用buildozer创build一个我的Kivy应用程序的Android包,但是当我试图包含numpy时候出现这个错误: 错误的恢复: compile options: '-DNO_ATLAS_INFO=1 -Inumpy/core/include -Ibuild/src.linux-x86_64-2.7/numpy/core/include/numpy -Inumpy/core/src/private -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -Inumpy/core/include -I/home/joao/github/buildozer/.buildozer/android/platform/python-for-android/build/python-install/include/python2.7 -Ibuild/src.linux-x86_64-2.7/numpy/core/src/multiarray -Ibuild/src.linux-x86_64-2.7/numpy/core/src/umath -c' ccache: numpy/linalg/lapack_litemodule.c ccache: numpy/linalg/python_xerbla.c /usr/bin/gfortran -Wall -lm build/temp.linux-x86_64-2.7/numpy/linalg/lapack_litemodule.o build/temp.linux-x86_64-2.7/numpy/linalg/python_xerbla.o -L/usr/lib -L/home/joao/github/buildozer/.buildozer/android/platform/python-for-android/build/python-install/lib -Lbuild/temp.linux-x86_64-2.7 -llapack -lblas -lpython2.7 -lgfortran -o build/lib.linux-x86_64-2.7/numpy/linalg/lapack_lite.so /usr/bin/ld: build/temp.linux-x86_64-2.7/numpy/linalg/lapack_litemodule.o: Relocations in generic ELF (EM: 40) /usr/bin/ld: build/temp.linux-x86_64-2.7/numpy/linalg/lapack_litemodule.o: Relocations in generic ELF (EM: 40) build/temp.linux-x86_64-2.7/numpy/linalg/lapack_litemodule.o: error […]

numpy:函数同时max()和min()

numpy.amax()将在数组中find最大值,而numpy.amin()对最小值也是一样的。 如果我想find最大和最小,我必须调用这两个函数,这需要两次(非常大)的数组,这似乎很慢。 在numpy API中是否有一个函数,可以通过数据只查找一个最大值和最小值?

Numpy:用vector元素划分每一行

假设我有一个numpy数组: data = np.array([[1,1,1],[2,2,2],[3,3,3]]) 我有一个相应的“vector:” vector = np.array([1,2,3]) 我如何操作每一行的data来减去或分开,结果是: sub_result = [[0,0,0], [0,0,0], [0,0,0]] div_result = [[1,1,1], [1,1,1], [1,1,1]] 长话短说:我如何使用与每行对应的一维标量数组对一个二维数组的每一行执行操作?

如何将列表保存为Python中的numpy数组?

我需要知道是否有可能将一个Python列表保存为一个numPy数组。

如何在Python直方图中使用对数框

据我所知直方图function中的选项Log = True仅指y轴。 P.hist(d,bins=50,log=True,alpha=0.5,color='b',histtype='step') 我需要log10中的等分间隔。 有什么可以做到这一点?

如何将数据集分割/分割为训练和testing数据集,例如交叉validation?

将NumPy数组随机分为训练和testing/validation数据集的好方法是什么? 类似于Matlab中的cvpartition或cvpartition函数。