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:
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

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