【发布时间】:2014-06-20 08:28:30
【问题描述】:
我有一些代码:
# first round
curr_g = np.array([])
temp_g = np.array([1,2,3])
if curr_g is not None:
curr_g = temp_g
print "in is not none"
else:
curr_g = np.c_[curr_g, temp_g]
print "in is none"
print "curr_g: "
print curr_g
#second round
temp_g = np.array([4,5,6])
if curr_g is not None:
print "in is not none"
curr_g = temp_g
else:
print "in none"
curr_g = np.c_[curr_g, temp_g]
print "curr_g: "
print curr_g
上面的输出如下:
in is not none
curr_g:
[1 2 3]
in is not none
curr_g:
[4 5 6]
到底为什么这个条件两次都变成“不是没有”? curr_g 在被分配temp_g 之后,在第二轮中只是“not None”。
我的目标是在第一轮中,因为curr_g 是真正的空,它应该填充temp_g,第二次,它实际上应该连接到temp_g 并变成如下:
[
1 4
2 5
3 6
]
我该怎么做?
【问题讨论】:
标签: python arrays numpy stack concatenation