Answer by Mikolaj Buchwald for Flipping zeroes and ones in one-dimensional...
I also found a way to do it:In [1]: from numpy import arrayIn [2]: a = array([1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])In [3]: b = (~a.astype(bool)).astype(int)In [4]: print(a); print(b)[1 1 1 1 1...
View ArticleAnswer by YXD for Flipping zeroes and ones in one-dimensional NumPy array
A sign that you should probably be using a boolean datatypea = np.array([0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], dtype=np.bool)# orb = ~ab = np.logical_not(a)
View ArticleAnswer by John Greenall for Flipping zeroes and ones in one-dimensional NumPy...
another superfluous option:numpy.logical_not(a).astype(int)
View ArticleAnswer by heltonbiker for Flipping zeroes and ones in one-dimensional NumPy...
answer = numpy.ones_like(a) - a
View ArticleAnswer by gboffi for Flipping zeroes and ones in one-dimensional NumPy array
There must be something in your Q that i do not understand...AnywayIn [2]: from numpy import arrayIn [3]: a = array((1,0,0,1,1,0,0))In [4]: b = 1-aIn [5]: print a ; print b[1 0 0 1 1 0 0][0 1 1 0 0 1...
View ArticleFlipping zeroes and ones in one-dimensional NumPy array
I have a one-dimensional NumPy array that consists of zeroes and ones like so:array([0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])I'd like a quick way to just "flip" the values such that zeroes become...
View Article
More Pages to Explore .....