Python Learning Python -Beginner Question

  • Thread starter Thread starter poobar
  • Start date Start date
  • Tags Tags
    Python
AI Thread Summary
The discussion centers around translating MATLAB code to Python, specifically creating column vectors and handling image files. The user initially seeks help with creating column vectors in Python, finding that using numpy.transpose() works for their needs. However, they encounter an issue when trying to open a .tif image file using the Image module, receiving an AttributeError. Responses suggest that the Python Imaging Library (PIL) may not support .tif images, recommending converting the file to .png using ImageMagick as a workaround. Additionally, advice is given on correcting import statements, suggesting the use of "from PIL import Image" to properly access the Image.open() function. Overall, the conversation highlights common challenges faced by beginners transitioning from MATLAB to Python, particularly in data manipulation and image processing.
poobar
Messages
21
Reaction score
0
Learning Python --Beginner Question

Hey All,
I am translating a whole lot of code from MATLAB to Python/NumPy/SciPy. However, I am having a lot of trouble creating column vectors. I know that in MATLAB it would go like this:

a = [1,2,3,4,5,6,78], colvec = a'

if anyone know the answer of has any good hints, please answer!

thanks!
 
Technology news on Phys.org


numpy.transpose(...)
 


okay. good. that works, so thank you very much.

naturally, a new problem has presented itself. i think this one is somewhat more complicated.

i have an image.tif that i am trying to open as a matrix in python. i learned about the Image.open(...) but i get an error when i try to do this.

i typed in:

from Image import Image
im = Image.open('C:\...tif')

I get back:

AttributeError
C:\Users\student\Desktop\(<python console> in <module>()
AttributeError: class Image has no attribute 'open'


help?

thanks
 


nbo10 said:
numpy.transpose(...)
you can also use a.T
Also, you may want to keep a copy of Numpy for Matlab user handy.

I'm not sure tif images are supported by PIL.
According to the documentation, http://www.pythonware.com/library/pil/handbook/format-tiff.htm is supported.
Are you sure that you've instantiated the object correctly and given the correct object path?

Also, I think your import statements might be wonky, and that could be throwing off your references. Try
Import Image
Image.open
and
from PIL import Image
Image.open
 
Last edited by a moderator:
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.

Similar threads

Replies
10
Views
3K
Replies
3
Views
1K
Replies
3
Views
2K
Replies
4
Views
3K
Replies
8
Views
2K
Back
Top