Python Forum

Full Version: while creating a array using numpy.arrange, how to negate only the last 50 numbers?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
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)]