Reputation: 27
What does this code do?
climate_results = np.concatenate((climate_data, yields.reshape(1000, 1)), axis=1)
Note : I have a variable called climate_data and yields
Upvotes: 0
Views: 192
Reputation: 24059
numpy.concatenate()
, concatenate two arrays.
(in your code you have 1000 row for climate_data and in this example I have 2 row for climate_data and we should reshape to 1000 or 2 row that can concatenate two array) see this example:
climate_data = np.array([[1,2],[3,4]])
# array([[1, 2],
# [3, 4]])
yields = np.array([0,1])
# array([0, 1])
yields = np.array([0,1]).reshape(2,1)
# array([[0],
# [1]])
climate_results = np.concatenate((climate_data, yields.reshape(2, 1)), axis=1)
climate_results
Output:
array([[1, 2, 0],
[3, 4, 1]])
You can concatenate in axis=0
like below:
climate_data = np.array([[1,2],[3,4]])
yields = np.array([[0,1]])
# array([[0, 1]])
climate_results = np.concatenate((climate_data, yields), axis=0)
Output:
array([[1, 2],
[3, 4],
[0, 1]])
Upvotes: 1