You should be able to just do:
np.ndarray[double, ndim=1, mode="c"] arr = np.array([1,2,3], dtype=np.float64, order="c")
From the docs for np.array
:
order : {'C', 'F', 'A'}, optional
Specify the order of the array. If order is 'C' (default), then the
array will be in C-contiguous order (last-index varies the
fastest). If order is 'F', then the returned array
will be in Fortran-contiguous order (first-index varies the
fastest). If order is 'A', then the returned array may
be in any order (either C-, Fortran-contiguous, or even
discontiguous).
My understanding is that you only need to use np.ascontiguousarray
if the array you are trying to pass was generated from some non-contiguous slice of another array. If you are creating the array from scratch, it shouldn't be necessary.
For example:
a = np.arange(10)
a.flags['C_CONTIGUOUS'] # True
b = a[::2]
b.flags['C_CONTIGUOUS'] # False
c = np.ascontiguousarray(b)
c.flags['C_CONTIGUOUS'] # True
Also, perhaps consider using the typed memoryview interface
double[::1] arr = np.array([1,2,3], dtype=np.float64)