Re: Difference between array( [1,0,1] ) and array( [ [1,0,1] ] )

2019-06-21 Thread Stephen Tucker
Markos,

I can explain the difference from a non-numpy point of view - I hope you
will be able to see how this difference affects what you are trying to do
in numpy.

vector_1 is an np.array consisting of a three-element list, with the three
elements being 1, 0 and 1.

vector_2 is an np.array consisting (at the top level) of a one-element
list, with that element (at this top level) being a three-element list,
with these three elements (at the lower level) being 1, 0 and 1.

Stephen.




On Fri, Jun 21, 2019 at 7:29 AM Markos  wrote:

>
> 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
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Difference between array( [1,0,1] ) and array( [ [1,0,1] ] )

2019-06-21 Thread edmondo . giovannozzi
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


Re: Difference between array( [1,0,1] ) and array( [ [1,0,1] ] )

2019-06-21 Thread edmondo . giovannozzi
Keep also in mind that numpy is quite different from Matlab.
In Matlab every vaiable is a matrix of at least 2 dimensions.

This is not the case of numpy (and is not the case in Fortran too).
every array can have a different number of dimensions. The transposition of an 
array with just 1 dimension is not really meaningful.
On the other hand most of the time is not needed.
For example le have a matrix:
a = np.array([[1,2],[1,1]])
and an array:
b = np.array([0.1,0.2])
You can left multiply or right multiply it to this matrix without any need to 
transpose it  (as you have to do in Matlab):
a @ b
array([0.5,0.3])
b @ a
array([0.3,0.4])
Cheers,


 

 
-- 
https://mail.python.org/mailman/listinfo/python-list


pip vs python -m pip?

2019-06-21 Thread Malcolm Greene
64-bit Python 3.6.8 running on Windows with a virtual environment activated.

"pip -v" reports 19.0.3
"python -m pip" reports 19.1.1

Is this behavior by design or a bug?

My takeaway is that its better to run "python -m pip ..." vs "pip ..." when 
running pip related tasks.

Thoughts?

Malcolm
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pip vs python -m pip?

2019-06-21 Thread Bill Deegan
you must be picking up pip from a different python installl (or virtualenv)
than you are picking up python.
Check your %PATH%

On Fri, Jun 21, 2019 at 6:29 AM Malcolm Greene  wrote:

> 64-bit Python 3.6.8 running on Windows with a virtual environment
> activated.
>
> "pip -v" reports 19.0.3
> "python -m pip" reports 19.1.1
>
> Is this behavior by design or a bug?
>
> My takeaway is that its better to run "python -m pip ..." vs "pip ..."
> when running pip related tasks.
>
> Thoughts?
>
> Malcolm
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


How to force "python -m site" ENABLE_USER_SITE to false?

2019-06-21 Thread Malcolm Greene
Any suggestions on how one can force the "python -m site" ENABLE_USER_SITE 
value to false?

Is it possible to globally force this setting - across all users - when 
installing a system wide version of Python ... or via a command line option 
when starting a Python session?

Motivation: When ENABLE_USER_SITE is true, packages can get accidentally 
installed in user specific Python\Python3XX\site-packages folder, overriding 
system packages and ... apparently (at least under Windows) ... virtual 
environment packages as well.

Thank you,
Malcolm
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pip vs python -m pip?

2019-06-21 Thread Malcolm Greene
> you must be picking up pip from a different python install (or virtualenv) 
> than you are picking up python.
> Check your %PATH%

That was our first guess. Only one version of Python installed on the system 
(we install on an empty, freshly serviced pack Windows VM). Only one version of 
python*.exe found via Explorer.

This behavior observed across multiple Windows 2016 Enterprise servers and 
Windows 10 Professional desktops.

Malcolm
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pip vs python -m pip?

2019-06-21 Thread Thomas Jollans
On 21/06/2019 15.27, Malcolm Greene wrote:
> 64-bit Python 3.6.8 running on Windows with a virtual environment activated.
>
> "pip -v" reports 19.0.3
> "python -m pip" reports 19.1.1
>
> Is this behavior by design or a bug?

If the pip and python executables you're calling both live in the
virtual environment, then it might be a bug

> My takeaway is that its better to run "python -m pip ..." vs "pip ..." when 
> running pip related tasks.

It's a good rule of thumb. When you have multiple versions of Python
installed side-by-side, there can be a danger that you call the wrong
'pip' by accident.


I don't think this should be a concern in a virtual environment though

Thomas

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pip vs python -m pip?

2019-06-21 Thread Chris Angelico
On Fri, Jun 21, 2019 at 11:55 PM Malcolm Greene  wrote:
>
> > you must be picking up pip from a different python install (or virtualenv) 
> > than you are picking up python.
> > Check your %PATH%
>
> That was our first guess. Only one version of Python installed on the system 
> (we install on an empty, freshly serviced pack Windows VM). Only one version 
> of python*.exe found via Explorer.
>
> This behavior observed across multiple Windows 2016 Enterprise servers and 
> Windows 10 Professional desktops.
>

Well, I'm pretty confident this isn't an actually desired behaviour,
so to answer your original question, I'd say "bug" is the more
accurate choice. That said, though... there are a LOT of ways that the
Windows path can fail to pick up the correct 'pip'. Normally
activating a venv should let you use "pip" to mean the right thing
just as "python" does, but maybe something's cached?

Are you doing this in cmd.exe, powershell, bash, or some other shell?

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to force "python -m site" ENABLE_USER_SITE to false?

2019-06-21 Thread Ed Leafe
On Jun 21, 2019, at 8:49 AM, Malcolm Greene  wrote:
> 
> Any suggestions on how one can force the "python -m site" ENABLE_USER_SITE 
> value to false?
> 
> Is it possible to globally force this setting - across all users - when 
> installing a system wide version of Python ... or via a command line option 
> when starting a Python session?

>From StackOverflow: 
>https://stackoverflow.com/questions/25584276/how-to-disable-site-enable-user-site-for-an-environment

-- Ed Leafe





-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to force "python -m site" ENABLE_USER_SITE to false?

2019-06-21 Thread Malcolm Greene
> From: Ed Leafe 
> StackOverflow: 
> https://stackoverflow.com/questions/25584276/how-to-disable-site-enable-user-site-for-an-environment

Thanks Ed! My takeaway from the above article and our path going forward is to 
explictly force ENABLE_USER_SITE to false via Python's "-s" switch.

Malcolm
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pip vs python -m pip?

2019-06-21 Thread Malcolm Greene
> From: Chris Angelico 
> Are you doing this in cmd.exe, powershell, bash, or some other shell?

Same result via cmd.exe and PowerShell (ps1).

> There are a LOT of ways that the Windows path can fail to pick up the correct 
> 'pip'. Normally activating a venv should let you use "pip" to mean the right 
> thing just as "python" does, but maybe something's cached?

I think you're on to something. Running pip as a package (python -m pip) will 
force the use of the virtual env copy of pip. Running pip as an application vs 
package may use the system version of pip.

Malcolm
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pip vs python -m pip?

2019-06-21 Thread Skip Montanaro
Malcolm> Running pip as a package (python -m pip) will force the use
of the virtual env copy of pip. Running pip as an application vs
package may use the system version of pip.

I believe it is for just this reason that the recommended spelling
these days is "python -m pip".

Skip
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Difference between array( [1,0,1] ) and array( [ [1,0,1] ] )

2019-06-21 Thread MRAB

On 2019-06-21 02:39, Markos wrote:


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?

By similar reasoning, why not 3-dimensional (layer, row, column)? Or 
4-dimensional?

--
https://mail.python.org/mailman/listinfo/python-list