# C Contiguous Array in PyCall

**URL:** <https://discourse.julialang.org/t/c-contiguous-array-in-pycall/133559>\
**Category:** General Usage\
**Tags:** question, array, python\
**Created:** [October 30, 2025, 2:19pm UTC](https://discourse.julialang.org/t/c-contiguous-array-in-pycall/133559 "2025-10-30T14:19:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frauke](https://avatars.discourse-cdn.com/v4/letter/f/b5e925/32.png) [@Frauke](https://discourse.julialang.org/u/Frauke)\
**Post date:** [October 30, 2025, 2:19pm UTC](https://discourse.julialang.org/t/c-contiguous-array-in-pycall/133559/1 "2025-10-30T14:19:36Z")

</div>

Hey everyone,

I am trying to communicate with a National Instrument DAQ via PyCall.jl and the NI Python library nidaqmx. For some functions I have to pass a C contiguous array (flag C\_CONTIGUOUS has to be true).

I tried to create a C contiguous array using PyCall and np.ascontiguousarray but the C\_CONTIGUOUS flag stays false. Here is my minimal working example:

```Julia
using PyCall
np = pyimport("numpy")
nidaqmx = pyimport("nidaqmx")

data = ones(10)
dataMatrix = repeat(reshape(data, 1, :), 2, 1)

dataMatrix_np = PyObject(np.ascontiguousarray(np.array(dataMatrix, dtype=np.float64, copy=true)))

println("Data matrix flags: $(dataMatrix_np.flags)")

```

This results in:

```Julia
Data matrix flags: PyObject C_CONTIGUOUS : False
  F_CONTIGUOUS : True
  OWNDATA : False
  WRITEABLE : True
  ALIGNED : True
  WRITEBACKIFCOPY : False

```

I would be very thankful for any advice on this!  
Frauke

---

<div class="post-metadata">

**Author:** ![Frauke](https://avatars.discourse-cdn.com/v4/letter/f/b5e925/32.png) [@Frauke](https://discourse.julialang.org/u/Frauke)\
**Post date:** [October 30, 2025, 3:42pm UTC](https://discourse.julialang.org/t/c-contiguous-array-in-pycall/133559/2 "2025-10-30T15:42:09Z")

</div>

Actually, I found a related post and this does the trick:

```julia-auto
using PyCall
np = pyimport("numpy")
nidaqmx = pyimport("nidaqmx")

data = ones(10)
dataMatrix = repeat(reshape(data, 1, :), 2, 1)

dataMatrix_np = PyReverseDims(dataMatrix)

println("Data matrix flags: $(dataMatrix_np.flags)")

```

Here is the link to the post:

> [@Equivalent of numpy.ascontiguousarray in Julia](https://discourse.julialang.org/t/equivalent-of-numpy-ascontiguousarray-in-julia/4525):
>
> I would like to change a non-contiguous array to a contiguous one. What is the fastest way to do that in Julia?

---

<div class="post-metadata">

**Author:** ![eldee](https://avatars.discourse-cdn.com/v4/letter/e/b5a626/32.png) [@eldee](https://discourse.julialang.org/u/eldee)\
**Post date:** [October 30, 2025, 6:19pm UTC](https://discourse.julialang.org/t/c-contiguous-array-in-pycall/133559/3 "2025-10-30T18:19:45Z")

</div>

If you’re fine with switching to PythonCall.jl, which does not automatically convert a NumPy array into an `Array`, you could alternatively just use

```julia
dataMatrix_np = np.ascontiguousarray(np.array(dataMatrix, dtype=np.float64, copy=true))
# type is Py, while for PyCall this would be Matrix{Float64}

```

or simply

```julia
dataMatrix_np = np.array(dataMatrix, dtype=np.float64, copy=true, order="C")

```

If you want to convert back to a Julia `::AbstractArray`, you can use `PyArray(dataMatrix_np)`/`pyconvert(PyArray, dataMatrix_np)` (wraps, row-major) or `pyconvert(Array, dataMatrix_np)` (copies, column-major).
