Learning Python -Beginner Question

  • Thread starter poobar
  • Start date
  • Tags
    Python
In summary, the conversation is about a beginner learning Python and having trouble creating column vectors and opening a tif image as a matrix. They received a solution for creating column vectors using numpy.transpose() and a suggestion to convert the tif image to a png before opening it using matplotlib or PIL. There is also a mention of a potential issue with the import statements.
  • #1
poobar
21
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
  • #2


numpy.transpose(...)
 
  • #3


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
 
  • #4
  • #5


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:

Related to Learning Python -Beginner Question

1. What is Python?

Python is a high-level, interpreted programming language that is widely used for web development, data analysis, artificial intelligence, and scientific computing. It is known for its simple syntax and easy-to-learn nature, making it a popular language for beginners.

2. Why should I learn Python?

Python is a versatile language that can be used for a variety of purposes. It is a preferred language for data science and machine learning due to its rich set of libraries and frameworks. It is also widely used in web development, game development, and automation. Learning Python can open up many career opportunities and provide a strong foundation for learning other programming languages.

3. Is Python suitable for beginners?

Yes, Python is considered to be one of the best programming languages for beginners. Its simple syntax, readability, and extensive community support make it easy to learn. It also has a large number of resources and tutorials available online for beginners.

4. What are the basic concepts I need to know to learn Python?

To learn Python, you should have a basic understanding of programming concepts such as variables, data types, control structures, and functions. Familiarity with object-oriented programming (OOP) concepts can also be helpful, but it is not necessary for learning Python.

5. How long does it take to learn Python?

The time it takes to learn Python depends on your learning pace and dedication. With consistent practice and effort, you can learn the basics of Python in a few weeks. However, mastering the language and its advanced concepts can take several months or even years. It is important to continue learning and practicing to improve your skills and stay up-to-date with new developments in the language.

Similar threads

  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
10
Views
2K
  • Programming and Computer Science
Replies
5
Views
2K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
7
Views
878
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
  • Science and Math Textbooks
Replies
7
Views
1K
  • Programming and Computer Science
Replies
3
Views
474
  • Programming and Computer Science
Replies
8
Views
1K
Back
Top