Convert numpy.ndarray into "normal" array

Johannes Bauer dfnsonfsduifb at gmx.de
Fri Apr 24 16:01:29 CEST 2009


MRAB schrieb:

>> <type 'numpy.ndarray'>
>> <type 'array'>
>>
>> So now I want to copy the fits_pixels -> pb_pixels. Doing
>>
>> pb_pixels = fits_pixels
>>
> This simply makes pb_pixels refer to the same object as fits_pixels. It
> doesn't copy the values into the existing pb_pixels object.

Oh okay, I was thinking of C++ std::vector<char> which behaves
differently :-/ Switching between languages back and forth is not
something I'm good in, appearently.

> You should be able to copy the values using array slicing, something
> like:
> 
>     pb_pixels[:] = fits_pixels
> 
> or:
> 
>     pb_pixels[:, :] = fits_pixels

OK, I hadn't been familiar with that syntax at all - need to catch up
reading on this.

However, it doesn't work (altough probably for another reason):

Traceback (most recent call last):
  File "./guiclient.py", line 433, in on_Result
    self.__updateresult()
  File "./guiclient.py", line 385, in __updateresult
    pb_pixels[:, :] = fits_pixels
TypeError: Array can not be safely cast to required type

I guess Python fears truncation. However I ensure in advance the values
won't be truncated. How can I convince Python that it may safely assume
that is true?

Kind regards,
Johannes

-- 
"Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit,
verlästerung von Gott, Bibel und mir und bewusster Blasphemie."
         -- Prophet und Visionär Hans Joss aka HJP in de.sci.physik
                         <48d8bf1d$0$7510$5402220f at news.sunrise.ch>



More information about the Python-list mailing list