To make final
an empty array of the same shape and dtype as content
, use:
final = np.empty_like(content)
Regarding the TypeError: integer argument expected, got float
:
Although the docstring for convolve1d says
origin : scalar, optional
The `origin` parameter controls the placement of the filter.
Default 0.0.
the origin
argument must be an integer, not a float.
Here is an example which runs without error:
import scipy.ndimage as ndimage
import numpy as np
# content = np.genfromtxt('Data.dat')
content = np.asarray(np.arange(750))
weights = np.array([1, 2, 4, 2, 1])
final = np.empty_like(content)
ndimage.convolve1d(content, weights, axis=-1, output=final, mode='reflect', cval=0.0,
origin=0
# origin=0.0 # This raises TypeError
)
print(final)
Uncommenting origin=0.0
raises the TypeError.
Regarding
with open("Data.dat", "r+") as f:
content = f.readlines()
content = [s.strip() for s in content]
content = np.asarray(content)
This makes content
an array of strings. Since you are taking a convolution, you must want an array of numbers. So instead replace the above with
content = np.genfromtxt('Data.dat')