小编use*_*991的帖子

numpy.shape中的L和数组的numpy.type中的32是什么?

我正在尝试numpy数组的功能,下面是代码:

import numpy as np

Z =np.array( 
    [[0,4,0,0,0,0],
     [0,0,0,1,0,0],
     [0,1,0,1,0,0],
     [0,0,1,1,0,0],
     [0,0,0,0,0,0],
     [0,0,0,0,0,0]])
print Z
print Z.dtype
print Z.shape
Run Code Online (Sandbox Code Playgroud)

这给了:

[[0 4 0 0 0 0]
 [0 0 0 1 0 0]
 [0 1 0 1 0 0]
 [0 0 1 1 0 0]
 [0 0 0 0 0 0]
 [0 0 0 0 0 0]]
int32
(6L, 6L)
Run Code Online (Sandbox Code Playgroud)

它是一个包含6行和6列的整数数组.但是numpy.hape中的32和numpy.shape中的L是什么?

python arrays numpy

13
推荐指数
2
解决办法
2万
查看次数

python中的timeit模块无法识别numpy模块

我想测试两个相同列表之间的处理时间,特别是正常列表和numpy列表.我的代码是

import timeit
import numpy as np

t = timeit.Timer("range(1000)")
print t.timeit()

u = timeit.Timer("np.arange(1000)")
print u.timeit()
Run Code Online (Sandbox Code Playgroud)

计算t很好,但对于uNameError:未列出全局名称'np'.

我应该如何编码以获得处理时间?

python numpy timeit

11
推荐指数
2
解决办法
5428
查看次数

如何使用numpy在一行中创建大小为10但第五个值为1的空向量

对于 numpy 模块,我可以用两行来完成:

x=np.zeros(10)
x[4]=1
Run Code Online (Sandbox Code Playgroud)

但是,我想知道是否可以将两者结合在一起

python numpy

5
推荐指数
1
解决办法
6993
查看次数

标签 统计

numpy ×3

python ×3

arrays ×1

timeit ×1