I have two numpy arrays:
我有两个numpy数组:
A = [ 186., 176., 158., 180., 186., 168., 168., 164., 178., 170., 189., 195.,
172., 187., 180., 186., 185., 168., 179., 178., 183., 179., 170., 175.]
B = [ -1., 60., 45., 58., 70., 70., 60., 64., 68., 78., 80., 78.,
66., 74., 84., 85., 75., 60., 71., 67., 88., -1., 70., 60.]
I want to stack only Positive values and I don't know how?
我只想把正的值叠加起来,我不知道怎么做?
I used numpy masked array to mask "-1"s from B
我使用numpy掩蔽数组来掩盖B中的“-1”s
thank you
谢谢你!
3 个解决方案
#1
4
Assuming you want to stack a
and b
for every position where b>=0
:
假设对于b>=0的每个位置都要堆栈a和b:
check = (b>=0)
c = np.vstack((a[check], b[check]))
should do the job...
应该做的工作……
#2
0
Maybe use an unsigned value for it?
也许用一个无符号的值?
unsigned int array[2] = {0, 1};
http://en.wikipedia.org/wiki/Integer_(computer_science)#value_and_representation
http://en.wikipedia.org/wiki/Integer_(computer_science)# value_and_representation
#3
0
If you only need to stack 1-dimensional arrays and the removal of negative numbers from B
will make its shape the same as A
, this should work:
如果你只需要堆叠一维数组,并且从B中去除负数将使其形状与A相同,这应该可以工作:
np.vstack( (A, B[B >= 0.0]) )
#1
4
Assuming you want to stack a
and b
for every position where b>=0
:
假设对于b>=0的每个位置都要堆栈a和b:
check = (b>=0)
c = np.vstack((a[check], b[check]))
should do the job...
应该做的工作……
#2
0
Maybe use an unsigned value for it?
也许用一个无符号的值?
unsigned int array[2] = {0, 1};
http://en.wikipedia.org/wiki/Integer_(computer_science)#value_and_representation
http://en.wikipedia.org/wiki/Integer_(computer_science)# value_and_representation
#3
0
If you only need to stack 1-dimensional arrays and the removal of negative numbers from B
will make its shape the same as A
, this should work:
如果你只需要堆叠一维数组,并且从B中去除负数将使其形状与A相同,这应该可以工作:
np.vstack( (A, B[B >= 0.0]) )