我有一些代碼:堆疊/連接數組和和「無」?
# 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
之後在第二輪中僅爲「非無」。
我的目標是,在第一輪,因爲curr_g
確實是空的,應當與temp_g
填充,而第二次,它實際上應該得到級聯到temp_g
,成爲如下:
[
1 4
2 5
3 6
]
我怎樣才能做到這一點?