Unlike many other data types, slicing an array into a new variable means that any changes to that new variable are broadcasted to the original variable. Put other way, a slice is a hotlink to the original array variable, not a seperate and independent copy of it.
import numpy as np
battleDeaths = np.array([1245, 2732, 3853, 4824, 5292, 6184, 7282, 81393, 932, 10834])
warStart = battleDeaths[0:3]; print('Death from battles at the start of war:', warStart)
warMiddle = battleDeaths[3:7]; print('Death from battles at the middle of war:', warMiddle)
warEnd = battleDeaths[7:10]; print('Death from battles at the end of war:', warEnd)
Death from battles at the start of war: [1245 2732 3853] Death from battles at the middle of war: [4824 5292 6184 7282] Death from battles at the end of war: [81393 932 10834]
warStart[0] = 11101
warStart
array([11101, 2732, 3853])
battleDeaths
array([11101, 2732, 3853, 4824, 5292, 6184, 7282, 81393, 932, 10834])
Note: This multidimensional array behaves like a dataframe or matrix (i.e. columns and rows)
regimentNames = ['Nighthawks', 'Sky Warriors', 'Rough Riders', 'New Birds']
regimentNumber = [1, 2, 3, 4]
regimentSize = [1092, 2039, 3011, 4099]
regimentCommander = ['Mitchell', 'Blackthorn', 'Baker', 'Miller']
regiments = np.array([regimentNames, regimentNumber, regimentSize, regimentCommander])
regiments
array([['Nighthawks', 'Sky Warriors', 'Rough Riders', 'New Birds'], ['1', '2', '3', '4'], ['1092', '2039', '3011', '4099'], ['Mitchell', 'Blackthorn', 'Baker', 'Miller']], dtype='<U12')
regiments[:,0]
array(['Nighthawks', '1', '1092', 'Mitchell'], dtype='<U12')
regiments[1,]
array(['1', '2', '3', '4'], dtype='<U12')
regiments[:2,2:]
array([['Rough Riders', 'New Birds'], ['3', '4']], dtype='<U12')