How to install matplotlib in Debian 9
Hi, I'm starting my studies with Python 3 on Debian 9 that I just installed. I have to install the matplotlib module, but I am in doubt what is the difference of the commands: pip3 install matplotlib or apt-get install python3-matplotlib Is there any difference in the packages which are installed? Thanks, Markos -- https://mail.python.org/mailman/listinfo/python-list
Re: How to install matplotlib in Debian 9
Em 08-06-2018 20:11, Jim Lee escreveu: On 06/08/2018 11:54 AM, Markos wrote: Hi, I'm starting my studies with Python 3 on Debian 9 that I just installed. I have to install the matplotlib module, but I am in doubt what is the difference of the commands: pip3 install matplotlib or apt-get install python3-matplotlib Is there any difference in the packages which are installed? Thanks, Markos It's generally preferable to use your distribution's package manager (apt-get) to install packages, as you will then receive updates as they become available. However, Debian is notorious for having stale/outdated packages in its repository. If you need the latest version of matplotlib, use pip (you'll have to update it manually). If you want old but stable, use apt-get. -Jim Hi Jim, As I prefer more stability than "updability" I will install the package: apt-get install python3-matplotlib Best Regards, Markos -- https://mail.python.org/mailman/listinfo/python-list
Difference between array( [1,0,1] ) and array( [ [1,0,1] ] )
Hi, I'm studying Numpy and I don't understand the difference between vector_1 = np.array( [ 1,0,1 ] ) with 1 bracket and vector_2 = np.array( [ [ 1,0,1 ] ] ) with 2 brackets The shape of vector_1 is: vector_1.shape (3,) But the shape of vector_2 is: vector_2.shape (1, 3) The transpose on vector_1 don't work: vector_1.T array([1, 0, 1]) But the transpose method in vector_2 works fine: vector_2.T array([[1], [0], [1]]) I thought that both vectors would be treated as an matrix of 1 row and 3 columns. Why this difference? Any tip? Thank you, Markos -- https://mail.python.org/mailman/listinfo/python-list
Re: Difference between array( [1,0,1] ) and array( [ [1,0,1] ] )
Thanks Edmondo, Stephen, Mats and Steven you for the tips, I studied linear algebra many years ago and I remember only a few rudiments. But I was trying to visualize (in a geometric way) how the numpy represents arrays, and what the geometrical meaning of the transpose operation made by numpy. I think I understood a little bit more. The number of nested brackets indicates the number of array dimensions. the vector ( [1,2] ) is one-dimensional, but the vector ( [ [1,2] ] ) is two-dimensional. v_1 = np.array( [1,2] ) > v_1.shape (2,) > v_1 v_1 > v_1 array( [1, 2] ) > v_2 = np.array( [ [1,2] ] ) > v_2.shape (1, 2) And it does not make sense to transpose a one-dimensional array. > v_1.T array( [1, 2] ) > v_2.T array( [ [1], [2] ] ) Anothe example: vector_1 = np.array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ) ^ vector_2 = np.array( [ [1, 2, 3, 4], [5, 6, 7, 8] ] ) ^ ^ vector_3 = np.array( [ [ [1,2], [3,4] ], [ [5,6], [7,8] ] ] ) ^ ^ ^ > vector_1 array([1, 2, 3, 4, 5, 6, 7, 8]) > vector_2 array( [ [1, 2, 3, 4], [5, 6, 7, 8] ] ) > vector_3 array( [ [ [1, 2], [3, 4] ], [ [5, 6], [7, 8] ] ] ) And looking for some tutorial about geometric aspects of matrices and the geometric meaning of the transpose I found that transposed is "mirrored along the diagonal" at: https://www.coranac.com/documents/geomatrix/ >vector_1.T array([1, 2, 3, 4, 5, 6, 7, 8]) > vector_2.T array( [ [1, 5], [2, 6], [3, 7], [4, 8] ] ) > vector_3.T array( [ [ [1, 5], [3, 7]], [ [2, 6], [4, 8] ] ] ) Thank you, Markos Em 21-06-2019 07:44, edmondo.giovanno...@gmail.com escreveu: Every array in numpy has a number of dimensions, "np.array" is a function that can create an array numpy given a list. when you write vector_1 = np.array([1,2,1]) you are passing a list of number to thet function array that will create a 1D array. As you are showing: vector_1.shape will return a tuple with the sizes of each dimension of the array that is: (3,) Note the comma thta indicate that is a tuple. While if you write: vector_2 = np.array([[1,2,3]]) You are passing a list of list to the function array that will instruct it to crete a 2D array, even though the size of the first dimension is 1: vector_2.shape (1,3) It is still a tuple as you can see. Try: vector_3 = np.array([[1,2,3],[4,5,6]]) And you'll see that i'll return a 2D array with a shape: vector_3.shape (2,3) As the external list has 2 elements that is two sublists each with 3 elements. The vector_2 case is just when the external list has only 1 element. I hope it is more clear now. Cherrs, Il giorno venerdì 21 giugno 2019 08:29:36 UTC+2, Markos ha scritto: Hi, I'm studying Numpy and I don't understand the difference between vector_1 = np.array( [ 1,0,1 ] ) with 1 bracket and vector_2 = np.array( [ [ 1,0,1 ] ] ) with 2 brackets The shape of vector_1 is: vector_1.shape (3,) But the shape of vector_2 is: vector_2.shape (1, 3) The transpose on vector_1 don't work: vector_1.T array([1, 0, 1]) But the transpose method in vector_2 works fine: vector_2.T array([[1], [0], [1]]) I thought that both vectors would be treated as an matrix of 1 row and 3 columns. Why this difference? Any tip? Thank you, Markos -- https://mail.python.org/mailman/listinfo/python-list
Matplotlib import image as float32
Hi, I observed that matplotlib reads an image file (PNG) as float32: Please, how to read this file as int8 to get RGB in range of 0-255? Thank you, Markos import numpy as np import matplotlib.pyplot as plt import matplotlib.image as mpimg imagem = mpimg.imread('lenna.png') print (imagem) [[[0.8862745 0.5372549 0.49019608] [0.8862745 0.5372549 0.49019608] [0.8745098 0.5372549 0.52156866] ... print (imagem.dtype) float32 -- https://mail.python.org/mailman/listinfo/python-list
Re: Matplotlib import image as float32
Em 01-07-2019 18:03, Chris Angelico escreveu: On Tue, Jul 2, 2019 at 6:59 AM Markos wrote: Hi, I observed that matplotlib reads an image file (PNG) as float32: Please, how to read this file as int8 to get RGB in range of 0-255? Thank you, Markos import numpy as np import matplotlib.pyplot as plt import matplotlib.image as mpimg imagem = mpimg.imread('lenna.png') print (imagem) [[[0.8862745 0.5372549 0.49019608] [0.8862745 0.5372549 0.49019608] [0.8745098 0.5372549 0.52156866] ... print (imagem.dtype) float32 Seems like matplotlib is rescaling everything to be on the range 0 to 1. https://matplotlib.org/users/image_tutorial.html ChrisA Hi Chris, I found a workaround at: www.programcreek.com/python/example/99442/matplotlib.image.imread I don't know if is the most elegant but it worked. I replaced: imagem = mpimg.imread('lenna.png') by the command: imagem = (mpimg.imread('lenna.png') * 255).astype('uint8') Thanks, Markos -- https://mail.python.org/mailman/listinfo/python-list
Most efficient way to replace "," with "." in a array and/or dataframe
Hi, I have a table.csv file with the following structure: , Polyarene conc ,, mg L-1 ,,, Spectrum, Py, Ace, Anth, 1, "0,456", "0,120", "0,168" 2, "0,456", "0,040", "0,280" 3, "0,152", "0,200", "0,280" I open as dataframe with the command: data = pd.read_csv ('table.csv', sep = ',', skiprows = 1) and the variable "data" has the structure: Spectrum, Py, Ace, Anth, 0 1 0,456 0,120 0,168 1 2 0,456 0,040 0,280 2 3 0,152 0,200 0,280 I copy the numeric fields to an array with the command: data_array = data.values [:, 1:] And the data_array variable gets the fields in string format: [['0,456' '0,120' '0,168'] ['0,456' '0,040' '0,280'] ['0,152' '0,200' '0,280']] The only way I found to change comma "," to dot "." was using the method replace(): for i, line in enumerate (data_array): data_array [i] = ([float (element.replace (',', '.')) for element in data_array [i]]) But I'm wondering if there is another, more "efficient" way to make this change without having to "iterate" all elements of the array with a loop "for". Also I'm also wondering if there would be any benefit of making this modification in dataframe before extracting the numeric fields to the array. Please, any comments or tip? Thanks you, Markos -- https://mail.python.org/mailman/listinfo/python-list
Re: Most efficient way to replace ", " with "." in a array and/or dataframe
Em 22-09-2019 13:10, Piet van Oostrum escreveu: Markos writes: Hi, I have a table.csv file with the following structure: , Polyarene conc ,, mg L-1 ,,, Spectrum, Py, Ace, Anth, 1, "0,456", "0,120", "0,168" 2, "0,456", "0,040", "0,280" 3, "0,152", "0,200", "0,280" I open as dataframe with the command: data = pd.read_csv ('table.csv', sep = ',', skiprows = 1) [snip] Also I'm also wondering if there would be any benefit of making this modification in dataframe before extracting the numeric fields to the array. Please, any comments or tip? data = pd.read_csv ('table.csv', sep = ',', skiprows = 1, decimal=b',', skipinitialspace=True) Thank you for the tip. I didn't realize that I could avoid formatting problems in the dataframe or array simply by using the read_csv command with the correct parameters (sep and decimal). I searched for information about the meaning of the letter "b" in the parameter decimal=b',' but didn't find. I found that it also works without the letter b. Best Regards, Markos -- https://mail.python.org/mailman/listinfo/python-list
Re: Most efficient way to replace ", " with "." in a array and/or dataframe
Em 22-09-2019 13:10, Piet van Oostrum escreveu: Markos writes: Hi, I have a table.csv file with the following structure: , Polyarene conc ,, mg L-1 ,,, Spectrum, Py, Ace, Anth, 1, "0,456", "0,120", "0,168" 2, "0,456", "0,040", "0,280" 3, "0,152", "0,200", "0,280" I open as dataframe with the command: data = pd.read_csv ('table.csv', sep = ',', skiprows = 1) [snip] Also I'm also wondering if there would be any benefit of making this modification in dataframe before extracting the numeric fields to the array. Please, any comments or tip? data = pd.read_csv ('table.csv', sep = ',', skiprows = 1, decimal=b',', skipinitialspace=True) Thank you very much for all the contributions. I didn't realize that I could avoid formatting problems in the dataframe or array simply by using the read_csv command with the correct parameters (sep and decimal). I searched for information about the meaning of the letter b in the parameter but did not find it. I found that it also works without the letter b. Best Regards, Markos -- https://mail.python.org/mailman/listinfo/python-list
I can't access dataframe fields
Hi all, I created the following data frame (updated_distance_matrix) P1 P2 P4 P5 (P3, P6) P1 0,00 0,244307 0,367696 0,341760 0 P2 0.234307 0.00 0.194165 0.1443178 0 P4 0.366969 0.194165 0.00 0.284253 0 P5 0.341760 0.1443178 0.284253 0.00 0 (P3, P6) 0.00 0.00 0.00 0.00 0 I can change the fields of columns and rows P1-P5 without problems. But when I try to access the fields of the row, or column, (P3, P6) print (updated_distance_matrix_df.loc [clusters [i], last_cluster]) the message appears: KeyError: 'the label [P3, P6] is not in the [index]' If I change find the "loc" by "at" method appears the error: print (updated_distance_matrix_df.at [clusters [i], last_cluster]) TypeError: unhashable type: 'list' And if you simply leave: print (updated_distance_matrix_df [clusters [i], last_cluster]) gives the error: TypeError: unhashable type: 'list' A last_cluster variable is of type list: print (last_cluster, type (last_cluster)) ['P3', 'P6'] And a variable cluster [i] is a string: print (clusters [i], type (clusters [i])) P5 Any tip? Thank you, Markos -- https://mail.python.org/mailman/listinfo/python-list
Re: I can't access dataframe fields
Hi MRAB, I changed last_cluster to tuple(last_cluster). From: print (updated_distance_matrix_df.loc [clusters [i], last_cluster]) to print (updated_distance_matrix_df.loc [clusters [i], tuple(last_cluster)]) And worked. Thank you, Markos Em 15-02-2020 23:36, MRAB escreveu: On 2020-02-16 00:50, Markos wrote: Hi all, I created the following data frame (updated_distance_matrix) P1 P2 P4 P5 (P3, P6) P1 0,00 0,244307 0,367696 0,341760 0 P2 0.234307 0.00 0.194165 0.1443178 0 P4 0.366969 0.194165 0.00 0.284253 0 P5 0.341760 0.1443178 0.284253 0.00 0 (P3, P6) 0.00 0.00 0.00 0.00 0 I can change the fields of columns and rows P1-P5 without problems. But when I try to access the fields of the row, or column, (P3, P6) print (updated_distance_matrix_df.loc [clusters [i], last_cluster]) the message appears: KeyError: 'the label [P3, P6] is not in the [index]' The rows and columns have "(P3, P6)", but you're looking for "[P3, P6]". They aren't the same. If I change find the "loc" by "at" method appears the error: print (updated_distance_matrix_df.at [clusters [i], last_cluster]) TypeError: unhashable type: 'list' Is it expecting a tuple instead of a list? Tuples are hashable, lists are not. And if you simply leave: print (updated_distance_matrix_df [clusters [i], last_cluster]) gives the error: TypeError: unhashable type: 'list' A last_cluster variable is of type list: print (last_cluster, type (last_cluster)) ['P3', 'P6'] And a variable cluster [i] is a string: print (clusters [i], type (clusters [i])) P5 Any tip? Thank you, -- https://mail.python.org/mailman/listinfo/python-list
Errors in testing the SciPy installation
Hi, Following the guidelines of the book Learning SciPy for Numerical and Scientific Computing Second Edition I did the tests: >>> import scipy >>> scipy.test() and got some errors: Ran 23065 tests in 490.568s FAILED (KNOWNFAIL=60, SKIP=1795, errors=29) What should I do? Thank you, Markos -- https://mail.python.org/mailman/listinfo/python-list
Re: Covariance matrix syntax
Hi Meghna, I organized some tutorials about Machine Learning for Chemistry with Python. Where you can find some info about the use of Covariance Matrix that may help you. The originals are in Portugueese, but you can read using Google Translator: https://tinyurl.com/yybazx9n https://tinyurl.com/y29mule6 https://tinyurl.com/yxtg4tce Best Regards, Markos Em 19-10-2020 02:23, Meghna Karkera escreveu: Dear Sir I am unable to find the *formula for covariance* used in np.cov syntax in PYTHON given in link https://numpy.org/doc/stable/reference/generated/numpy.cov.html. Could you please help me out. Thanks Meghna On Tue, Oct 13, 2020 at 11:46 AM Christian Gollwitzer wrote: Am 13.10.20 um 06:52 schrieb Meghna Karkera: Could you let me know what is the back end calculation of this covariance matrix syntax np.cov You can look it up yourself: Go to the docs https://numpy.org/doc/stable/reference/generated/numpy.cov.html At the right hand side, just right of the function signature, there is a link [source]. Click there and it takes you to the implementation. Apparently it is done in straightforward Python. Christian PS: Snipped a lot of unrelated citation at the bottom On Tue, Oct 13, 2020, 10:14 Bruno P. Kinoshita < brunodepau...@yahoo.com.br> wrote: [...] I think the np.cov is from the numpy module (imported/aliased as np?). -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
How to install i1636
Please, How to install the ia636 library on Debian (Squeeze) with Python 2.6? Thank you, Markos -- https://mail.python.org/mailman/listinfo/python-list
Idle - ImportError: No module named numpy
Hi, I'm beginning to study the numpy. When I open a terminal (Debian Squeeze) and run the python interpreter the command "import numpy as np" run without errors. But when I run the same command on idle3 the following error appears. import numpy as np Traceback (most recent call last): File "", line 1, in import numpy as np ImportError: No module named numpy How configure idle to load the numpy module? Thanks, Markos -- https://mail.python.org/mailman/listinfo/python-list
OpenCV with Python (cv or cv2)
Hi, I want to use OpenCV with Python. I installed version 2.4.9 (http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.9/opencv-2.4.9.zip/) in debian Squeeze running Python 2.6.6. Using the tutorial: http://indranilsinharoy.com/2012/11/01/installing-opencv-on-linux/ (I tried to install versions 2.4.11 and 2.4.10 (in Squeeze with python 2.2.6) but I couldn't.) I lost some time trying to load the module cv2: >> Import cv2.cv the cv Traceback (most recent call last): File "", line 1, in > ImportError: No module named cv2.cv After a while I realized I could use the cv module. (import cv) But still I do not understand the differences between the modules cv and cv2. Do you suggest any good tutorial about the differences between cv and cv2? I will have to make many changes in python programs using cv to reuse the code later with cv2? Thanks, Markos -- https://mail.python.org/mailman/listinfo/python-list
Re: OpenCV with Python (cv or cv2)
Hi Laura, On 26-05-2015 11:21, Laura Creighton wrote: In a message of Tue, 26 May 2015 10:24:30 -0300, Markos writes: Hi, I want to use OpenCV with Python. I installed version 2.4.9 (http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.9/opencv-2.4.9.zip/) in debian Squeeze running Python 2.6.6. Using the tutorial: http://indranilsinharoy.com/2012/11/01/installing-opencv-on-linux/ (I tried to install versions 2.4.11 and 2.4.10 (in Squeeze with python 2.2.6) but I couldn't.) You mean python 2.6.6, right? and this package: https://packages.debian.org/source/squeeze/opencv which is 2.1.0-3 is too old for you? I installed this package (python-opencv) but I thought this package would be only some API for python to use the opencv library and I imagined that I would still have to install the opencv library from source. What do you mean that you tried to install versions 2.4.11 and 2.4.10 but couldn't? What error messages did you get? For example when trying to install the 2.4.11 version after running cmake: cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON .. (Output of cmake at the end of message.) and make -j2 to compile, but an error occurred after compiling 55%: [ 55%] Building CXX object modules/legacy/CMakeFiles/opencv_legacy.dir/src/facedetection.cpp.o Linking CXX shared library ../../lib/libopencv_legacy.so [ 55%] Built target opencv_legacy make: ** [all] Erro 2 I lost some time trying to load the module cv2: Import cv2.cv the cv s/the/as/ ? import cv2.cv as cv Traceback (most recent call last): File "", line 1, in> ImportError: No module named cv2.cv After a while I realized I could use the cv module. (import cv) But still I do not understand the differences between the modules cv and cv2. Do you suggest any good tutorial about the differences between cv and cv2? I will have to make many changes in python programs using cv to reuse the code later with cv2? Thanks, Markos -- https://mail.python.org/mailman/listinfo/python-list post the output you got from cmake At the end of message. It will probably complain that it is missing some headers, so couldn't make libcv2.so If you haven't installed python-dev (not just python) and numpy I guarantee it will not find needed headers; if you have but it is still not being made we will have to look harder at what is going wrong. I installed the following packages: apt-get install cmake apt-get install build-essential apt-get install pkg-config apt-get install libgtk2.0-dev apt-get install python-opencv python-dev python-numpy apt-get install libpng12-0 libpng12-dev libpng++-dev libpng3 libpnglite-dev libpngwriter0-dev libpngwriter0c2 zlib1g-dbg zlib1g zlib1g-dev pngtools libjasper-dev libjasper-runtime libjasper1 libjpeg8 libjpeg8-dbg libjpeg62 libjpeg62-dev libjpeg-progs libtiff4-dev libtiff4 libtiffxx0c2 libtiff-tools ffmpeg libavcodec-dev libavcodec52 libavformat52 libavformat-dev libswscale0 libswscale-dev openexr libopenexr6 libopenexr-dev apt-get install libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libxine1-ffmpeg libxine-dev libxine1-bin libunicap2 libunicap2-dev libucil2 libucil2-dev libdc1394-22-dev libdc1394-22 libdc1394-utils libv4l-0 libv4l-dev apt-get install libqt4-dev If it made a libcv.so for you, did it put it in a place you can see with your PYTHONPATH? Laura >>> import sys >>> print sys.path ['', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/local/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages/PIL', '/usr/lib/python2.6/dist-packages/gst-0.10', '/usr/lib/pymodules/python2.6', '/usr/lib/pymodules/python2.6/gtk-2.0', '/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode'] import cv works fine but I didn't find libcv.so in my system. I suppose that cv had already been installed by the package python-opencv, and the compilation of the opencv didn't install cv2. Thanks for your attention, Markos Return of cmake -- Linker flags (Release): -- Linker flags (Debug): -- Precompiled headers: YES -- -- OpenCV modules: -- To be built: core flann imgproc highgui features2d calib3d ml video legacy objdetect photo gpu ocl nonfree contrib stitching superres ts videostab -- Disabled:world -- Disabled by dependency: - -- Unavailable:
Re: OpenCV with Python (cv or cv2)
Hi Laura, I will follow your advice and install Debian 8.0. I was postponing this upgrade. :^) I just find that Jessie is the new stable release. According to the tutorial: http://milq.github.io/install-opencv-ubuntu-debian/ the simplest way to install opencv in jessie is: apt-get install python-dev libopencv-opencv And from what I saw the opencv package available in the repository is 2.4.9 https://packages.debian.org/jessie/python-opencv And from what I saw on the site: https://packages.debian.org/jessie/python3 and https://packages.debian.org/jessie/python There are packages in the repository for python 3.4.2-2 and 2.7.9-1 My doubt is which version of Python (3.4.2-2 or 2.7.9-1) is compatible with the opencv library 2.4.9 available in the repository? Thanks for your attention, Markos On 28-05-2015 01:47, Laura Creighton wrote: Your cmake output doesn't mention that it tried to build libcv.so so, I guess the reason you cannot find it is that it never tried to make it. You may already have fixed your problem by just installing the relevant debian package. If not, it may be that you need to install this one https://packages.debian.org/squeeze/libcv-dev to get libcv. You have another problem. Squeeze is _very_ old. According to http://stackoverflow.com/questions/5212728/libcxcore-so-2-missing-in-opencv the opencv project renamed a bunch of libraries, so if at all possible you should upgrade your debian distribution. You may have all sorts of mismatches between the source you just built and the libraries you need -- which you will only find by trial and error. Laura -- https://mail.python.org/mailman/listinfo/python-list