

Instead it just adds an extra dimension to the individual column arrays (making them shape (120560400, 1) without copying the data) and then concatenates old and new columns together in one operation. This avoids the np.stack operation, which is an additional copy of the new column data. Img_as_array = np.concatenate( + new_columns], axis=1)

Img_as_array = np.concatenate(, axis=1)Įdit: Actually, it is likely a lot more efficient if you replace the last two lines with this: new_columns = The append() method in the Python programming language adds an item to a list that already exists whereas the extend() method adds each of the iterable elements. # The above are all (120560400,) arrays, stack them together into one (120560400, 6) array Object that defines the index or indices before which values is inserted. Insert values along the given axis before the given indices. Post_NDVI = (img_as_array - img_as_array)/(img_as_array + img_as_array) numpy.insert(arr, obj, values, axisNone) source. Pre_NDVI = (img_as_array - img_as_array)/(img_as_array + img_as_array) hsplit Split array into multiple sub-arrays horizontally (column wise). concatenate Join a sequence of arrays along an existing axis. values : arraylikevalues to be added in the arr. See also append Append elements at the end of an array. The numpy.append () appends values along the mentioned axis at the end of the array Syntax : numpy.append (array, values, axis None) Parameters : array : arraylikeInput array. If axis is None, out is a flattened array. split Split array into a list of multiple sub-arrays of equal size. Note that insert does not occur in-place: a new array is returned. arraysplit Split an array into multiple sub-arrays of equal or near-equal size. Post_NBR = (img_as_array - img_as_array)/(img_as_array + img_as_array) See also ma.concatenate Concatenate function that preserves input masks. Vectorizing in this case is easy, since you can apply arithmetic operators like those to whole arrays and they will work element-wise, outsourcing the loop over the 120560400 rows to the much more efficient C implementations of NumPy: pre_NBR = (img_as_array - img_as_array)/(img_as_array + img_as_array)
