I am switching from Python to C code for the purpose of my project. As I try to manipulate an array, it is very different from what I used to do in python. So I just want to know some "equivalent" operations for an array in C and Python.
So for numpy array in Python, we can directly sum(or other operations) up two arrays elementwise easily. In a sense, I think numpy array is like a virtual "matrix" that you can manipulate with as if it is stored as a whole(at least appear to).
For C array, it looks like a different animal. From what I could search out from the internet, I have to use for loop in order to do these basic operations. I think an array in C is just a set of values that are stored in addresses next to each other in order.
I know that C is much faster than Python, but I also know for loop is a nasty thing that should be avoided as possible in Python. Isn't these for loops in C slow the program down?(though I think when I use numpy module in Python, the module takes care of these for loops implicitly)
I also get a confusion about pointer. Consider this function that takes in a 1D array:
int myfunc(int *myarray);
{
int sum=0;
for(int i=0; i<sizeof(myarray); i++)
{
sum += myarray[i];
}
return sum
}
Suppose I input some array say "arr", then I let:
*myarray = arr
Thus, later in the function when I am calling lines such as:
sum += myarray[i]
I am actually doing this:
sum += &arr
Which is really confusing. For me, it looks like I am directly adding addresses of variables with values of other variables. Is this code wrong or I misunderstand pointer?