Learning Python -Beginner Question

  • Context: Python 
  • Thread starter Thread starter poobar
  • Start date Start date
  • Tags Tags
    Python
Click For Summary

Discussion Overview

The discussion revolves around a beginner's challenges in translating code from MATLAB to Python, specifically focusing on creating column vectors and opening TIFF image files using Python libraries.

Discussion Character

  • Technical explanation
  • Homework-related
  • Debate/contested

Main Points Raised

  • One participant seeks assistance in creating column vectors in Python, referencing MATLAB syntax.
  • Another participant suggests using numpy.transpose(...) as a solution for creating column vectors.
  • A participant confirms that the suggested method works but encounters a new issue with opening a TIFF image file.
  • There is uncertainty about whether TIFF images are supported by the Python Imaging Library (PIL), with one participant mentioning conflicting information.
  • Another participant proposes a workaround of converting the TIFF file to PNG using ImageMagick before opening it with matplotlib or PIL.
  • One participant questions the correctness of the import statements used to open the image and suggests alternative import methods.

Areas of Agreement / Disagreement

Participants express differing views on the support for TIFF images in PIL, and there is no consensus on the best approach to resolve the image opening issue.

Contextual Notes

There are limitations regarding the assumptions about library support for TIFF files and the correctness of the import statements, which remain unresolved.

Who May Find This Useful

Beginners in Python programming, particularly those transitioning from MATLAB, and individuals interested in image processing with Python.

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:

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 7 ·
Replies
7
Views
5K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K