Python Forum
while creating a array using numpy.arrange, how to negate only the last 50 numbers? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: while creating a array using numpy.arrange, how to negate only the last 50 numbers? (/thread-17240.html)



while creating a array using numpy.arrange, how to negate only the last 50 numbers? - vicky53 - Apr-03-2019

I'm creating an array using numpy and trying to negate the numbers from 50 to 100 in seperate steps as below..
\\

arr = np.arange(100)
arr1 = arr[50:100]*-1
arr2=(arr[0:50])
result=np.concatenate([arr2,arr1])
Is it possible to negate the intended numbers in the first step itself?


RE: while creating a array using numpy.arrange, how to negate only the last 50 numbers? - scidam - Apr-06-2019

The resulting array includes a gap. np.arange can not produce arrays with gaps.

arr = np.arange(100)
arr[50:] *= -1
np.r_[np.arange(50), np.arange(-50, -99, -1)]