Confused about extending.
Joonas Paalasmaa
joonas at olen.to
Thu Feb 22 08:44:59 EST 2001
>> I have made the following C-function and now I would like to
>> use it via Python in that way, that it would
>> manipulate Python lists smoothedValues and originalValues.
>> But I am just a beginner with C and I got confused with extending HowTo.
>> I would be glad if someone would explain how to manipulate the code to
>> make it extendingable.
>>
>> Joonas.
>
>
> I'm puzzled as to why you have implemented this function in C instead of
> Python. Is it for
> speed? Just how big ARE your lists?
My lists are big so that is the reason why I have to make
the processing with C. But the frontend must be Python and C-module
would be used from Python. For example:
##############
import cListprocessor
list = [1,2,3,4,5,6,7,8,9,15,9,8,7,6,5,4,3,2,1]
processedList = cListprocessor.SmoothedList(list)
##############
- Joonas Paalasmaa
>> void SmoothedList(double *originalValues, double *smoothedValues,
>> int listSize, int filterSize)
>> {
>> double tmpResult;
>> int i, j;
>> int iterations = listSize - filterSize + 1;
>>
>> for(i = 0; i < iterations; i++)
>> {
>> for(j = 0, tmpResult = 0.0; j < filterSize; j++)
>> tmpResult += originalValues[i + j];
>> smoothedValues[i] = tmpResult / (double)filterSize;
>> }
>> }
>
>
> def SmoothedList(originalValues, smoothedValues, listSize, filterSize)
> iterations = listSize - filterSize + 1;
> for i in range(0,iterations):
> tmpResult = 0.0
> for j in range(0, filterSize):
> tmpResult = tmpResult + originalValues[i + j]
> smoothedValues[i] = tmpResult / filterSize
>
> ------------------------------------
> Have I missed something here?
More information about the Python-list
mailing list