I have a simple function that is supposed to run down the diagonal of an array and turn all the values to 0.
def diagonal_zeros(dataset):
zero = dataset[:]
length = len(zero)
for i in range(length):
zero[i, i] = 0
return zero
When I run this function on an array, it outputs the new, correct 'zero' array, but it also goes back and overwrites the original 'dataset.' I had thought that the line zero = dataset[:] would have prevented this.
I do not, however, get the same behavior with this function:
def seperate_conditions(dataset, first, last):
dataset = dataset[first:last, :]
return dataset
Which leaves the first dataset unchanged. I've been reading StackOverflow answers to related questions, but I cannot for the life of me figure this out. I'm working on a scientific analysis pipeline so I really want to be able to refer back to the matrices at every step.
Thanks
numpy, I presume.numpyslicing returns a view, not a copy.