title: Caling a C function from python, with an array as input to the function
body: <p>I am giving an array as an input to the C code.</p>
  
  <p>The C code is as follows:</p>
  
  <pre><code>int ECG(int* ECG_sample)
  {
     for (int i=0;i&lt;sizeof(ECG_sample);i++)
     {
        ecg_wave_sample = ECG_sample[i];
        Filter_CurrentECG_sample(&amp;ecg_wave_sample, &amp;ecg_filterout);  
        Calculate_HeartRate(ecg_filterout,&amp;global_HeartRate); // calculate HeartRate
        printf("%d\n",global_HeartRate);
     }
     return global_HeartRate;
  }
  </code></pre>
  
  <p>I need to call this function in python. I have saved the name of the file as <code>ECG.c</code>. I used the command <code>cc -fPIC -shared -o ECG.so ECG.c</code>. </p>
  
  <p>I used <code>ctypes</code> to call the c function like this</p>
  
  <pre><code>import ctypes
  from ctypes import *
  import numpy as np
  so_file = "/home/yasaswini/hp2-notebooks/notebooks/Algorithm_testing_on_database/ECG.so"
  ECG_sample = np.zeros(2000,dtype=np.int32)
  ECG_sample = [4,5,6....6,7]
  main_1 = CDLL(so_file)
  print(type(main_1)) \\line8
  print(main_1.ECG(ECG_sample))
  </code></pre>
  
  <p>I currently getting this error, even though both the inputs are arrays and int type.</p>
  
  <pre><code>ArgumentError Traceback (most recent call last)
  &lt;ipython-input-231-c871feac52f7&gt; in &lt;module&gt;
      2 #print(main.ECG(ECG_sample))
      3 #fun(ctypes.c_void_p(ECG_sample.ctypes.data))
      ----&gt; 4 print(main_1.ECG(ECG_sample))
  
  ArgumentError: argument 1: &lt;class 'TypeError'&gt;: Don't know how to convert parameter 1
  </code></pre>
  
  <p>I also tried <code>main_1(ctypes.c_void_p(ECG_sample.ctypes.data))</code> instead of line8. But I get this error</p>
  
  <pre><code>AttributeError Traceback (most recent call last)
  &lt;ipython-input-238-c96b4ca485d7&gt; in &lt;module&gt;
      1 #while(1):
      2 #print(main.ECG(ECG_sample))
      ----&gt; 3 main_1(ctypes.c_void_p(ECG_sample.ctypes.data))
      4 #print(main_1.ECG(ECG_sample))
  AttributeError: 'list' object has no attribute 'ctypes'
  </code></pre>
  
  <p>Can someone help me with is?</p>