How to concatenate two numpy arrays inside a function and return it considering the following program
#!/usr/bin/env python
import numpy as np
def myfunction(myarray = np.zeros(0)):
print "myfunction : before = ", myarray # This line should not be modified
data = np.loadtxt("test.txt", unpack=True) # This line should not be modified
myarray = np.concatenate((myarray, data))
print "myfunction : after = ", myarray # This line should not be modified
return # This line should not be modified
myarray = np.array([1, 2, 3])
print "main : before = ", myarray
myfunction(myarray)
print "main : after = ", myarray
The result of this code is :
main : before = [1 2 3]
myfunction : before = [1 2 3]
myfunction : after = [ 1. 2. 3. 1. 2. 3. 4. 5.]
main : after = [1 2 3]
And I want :
main : before = [1 2 3]
myfunction : before = [1 2 3]
myfunction : after = [ 1. 2. 3. 1. 2. 3. 4. 5.]
main : after = [ 1. 2. 3. 1. 2. 3. 4. 5.]
How to modify the provided program to get the expected result (the 4 lines marked by # This line should not be modified should remain the same) ?
myarrayin-place, you certainly wouldn't want to combine that with it having a default value (myarray = np.zeros(0)).