python - Numpy Deep Copy Array -
i'm having trouble copying array using numpy. i'm running few different sort functions , comparing run times, need copy of original array , 1 modify. here's code i've got.
import numpy import random size = 10 display = true def random_fill(): return numpy.array([random.random()*10000 in range(size)]) def copy(p): return numpy.copy(p) def display(p): if (display): print print def bubble_sort(array): temp = 0 in range(size, 1, -1): j in range(1, i): if (array[j-1] > array[j]): temp = array[j-1] array[j-1] = array[j] array[j] = temp = random_fill() b = copy(a) display(a) display(b) bubble_sort(a) display(a) display(b) first a , b display properly, being random array. a sorts , displays correctly b displays a is. b should remain unsorted. what's issue here?
you shouldn't use print a print p otherwise print global array instead of 1 passed function.
Comments
Post a Comment