[issue39218] Assertion failure when calling statistics.variance() on a float32 Numpy array

2021-08-30 Thread Raymond Hettinger
Change by Raymond Hettinger : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker ___

[issue39218] Assertion failure when calling statistics.variance() on a float32 Numpy array

2021-08-30 Thread Raymond Hettinger
Raymond Hettinger added the comment: New changeset 793f55bde9b0299100c12ddb0e6949c6eb4d85e5 by Raymond Hettinger in branch 'main': bpo-39218: Improve accuracy of variance calculation (GH-27960) https://github.com/python/cpython/commit/793f55bde9b0299100c12ddb0e6949c6eb4d85e5 --

[issue39218] Assertion failure when calling statistics.variance() on a float32 Numpy array

2021-08-26 Thread Raymond Hettinger
Raymond Hettinger added the comment: > what it's correcting for is an inaccurate value of "c" [...] I'll leave the logic as-is and just add a note about what is being corrected. > Numerically, it's probably not helpful. To make a difference, the mean would have to have huge magnitude

[issue39218] Assertion failure when calling statistics.variance() on a float32 Numpy array

2021-08-26 Thread Mark Dickinson
Mark Dickinson added the comment: > what it's correcting for is an inaccurate value of "c" [...] In more detail: Suppose "m" is the true mean of the x in data, but all we have is an approximate mean "c" to work with. Write "e" for the error in that approximation, so that c = m + e. Then

[issue39218] Assertion failure when calling statistics.variance() on a float32 Numpy array

2021-08-26 Thread Mark Dickinson
Mark Dickinson added the comment: > The rounding correction in _ss() looks mathematically incorrect to me [...] I don't think it was intended as a rounding correction - I think it's just computing the variance (prior to the division by n or n-1) of the `(x - c)` terms using the standard

[issue39218] Assertion failure when calling statistics.variance() on a float32 Numpy array

2021-08-25 Thread Raymond Hettinger
Change by Raymond Hettinger : -- keywords: +patch pull_requests: +26406 stage: -> patch review pull_request: https://github.com/python/cpython/pull/27960 ___ Python tracker

[issue39218] Assertion failure when calling statistics.variance() on a float32 Numpy array

2021-08-25 Thread Raymond Hettinger
Raymond Hettinger added the comment: The rounding correction in _ss() looks mathematically incorrect to me: ∑ (xᵢ - x̅ + εᵢ)² = ∑ (xᵢ - x̅)² - (∑ εᵢ)² ÷ n If we drop this logic (which seems completely bogus), all the tests still pass and the code becomes cleaner: def _ss(data,

[issue39218] Assertion failure when calling statistics.variance() on a float32 Numpy array

2021-08-25 Thread Tal Einat
Change by Tal Einat : -- nosy: -taleinat ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue39218] Assertion failure when calling statistics.variance() on a float32 Numpy array

2021-08-20 Thread Raymond Hettinger
Raymond Hettinger added the comment: Removing the assertion and implementing Steven's idea seems like the best way to go: sum((y:=(x-c)) * y for x in data) -- ___ Python tracker

[issue39218] Assertion failure when calling statistics.variance() on a float32 Numpy array

2021-08-20 Thread Irit Katriel
Irit Katriel added the comment: I've reproduced this on 3.9 and 3.10. This part of the code in main is still the same, so the issue is probably there even though we don't have numpy with which to test. -- nosy: +iritkatriel versions: +Python 3.10, Python 3.11, Python 3.9 -Python 3.8

RE: Why can't numpy array be restored to saved value?

2020-11-26 Thread pjfarley3
> -Original Message- > From: Christian Gollwitzer > Sent: Thursday, November 26, 2020 3:26 AM > To: python-list@python.org > Subject: Re: Why can't numpy array be restored to saved value? > > Am 25.11.20 um 07:47 schrieb pjfarl...@earthlink.net: > > Why isn't t

RE: Why can't numpy array be restored to saved value?

2020-11-26 Thread pjfarley3
> -Original Message- > From: Greg Ewing > Sent: Thursday, November 26, 2020 12:01 AM > To: python-list@python.org > Subject: Re: Why can't numpy array be restored to saved value? > > On 25/11/20 7:47 pm, pjfarl...@earthlink.net wrote: > > Why isn't the fin

Re: Why can't numpy array be restored to saved value?

2020-11-26 Thread Christian Gollwitzer
Am 25.11.20 um 07:47 schrieb pjfarl...@earthlink.net: Why isn't the final value of the numpy array npary in the following code the same as the initial value before some but not all elements of the array were changed to a new value? I know I am missing something basic here. I thought I

Re: Why can't numpy array be restored to saved value?

2020-11-25 Thread Greg Ewing
On 25/11/20 7:47 pm, pjfarl...@earthlink.net wrote: Why isn't the final value of the numpy array npary in the following code the same as the initial value before some but not all elements of the array were changed to a new value? Slicing a numpy array doesn't copy anything, it just gives you

RE: Why can't numpy array be restored to saved value?

2020-11-25 Thread pjfarley3
t; -Original Message- > From: pjfarl...@earthlink.net > Sent: Wednesday, November 25, 2020 1:48 AM > To: 'python-list@python.org' > Subject: Why can't numpy array be restored to saved value? > > Why isn't the final value of the numpy array npary in the following code t

Why can't numpy array be restored to saved value?

2020-11-24 Thread pjfarley3
Why isn't the final value of the numpy array npary in the following code the same as the initial value before some but not all elements of the array were changed to a new value? I know I am missing something basic here. I thought I understood the concepts of immutable vs mutable values

Re: numpy array question

2020-04-02 Thread Peter Otten
jagmit sandhu wrote: > python newbie. I can't understand the following about numpy arrays: > > x = np.array([[0, 1],[2,3],[4,5],[6,7]]) > x > array([[0, 1], >[2, 3], >[4, 5], >[6, 7]]) > x.shape > (4, 2) > y = x[:,0] > y > array([0, 2, 4, 6]) > y.shape > (4,) > > Why is

Re: numpy array question

2020-04-02 Thread edmondo . giovannozzi
Il giorno giovedì 2 aprile 2020 06:30:22 UTC+2, jagmit sandhu ha scritto: > python newbie. I can't understand the following about numpy arrays: > > x = np.array([[0, 1],[2,3],[4,5],[6,7]]) > x > array([[0, 1], >[2, 3], >[4, 5], >[6, 7]]) > x.shape > (4, 2) > y = x[:,0] > y

numpy array question

2020-04-01 Thread jagmit sandhu
python newbie. I can't understand the following about numpy arrays: x = np.array([[0, 1],[2,3],[4,5],[6,7]]) x array([[0, 1], [2, 3], [4, 5], [6, 7]]) x.shape (4, 2) y = x[:,0] y array([0, 2, 4, 6]) y.shape (4,) Why is the shape for y reported as (4,) ? I expected it to be a

[issue39218] Assertion failure when calling statistics.variance() on a float32 Numpy array

2020-01-05 Thread Reed
Reed added the comment: Thank you all for the comments! Either using (x-c)*(x-c), or removing the assertion and changing the final line to `return (U, total)`, seem reasonable. I slightly prefer the latter case, due to Mark's comments about x*x being faster and simpler than x**2. But I am

[issue39218] Assertion failure when calling statistics.variance() on a float32 Numpy array

2020-01-05 Thread Mark Dickinson
Mark Dickinson added the comment: [Karthikeyan] > can possibly break again if (x-c) * (x-c) was also changed to return float64 > in future I think it's safe to assume that multiplying two NumPy float32's will continue to give a float32 back in the future; NumPy has no reason to give back a

[issue39218] Assertion failure when calling statistics.variance() on a float32 Numpy array

2020-01-05 Thread Steven D'Aprano
Steven D'Aprano added the comment: Nice analysis and bug report, thank you! That's pretty strange behaviour for float32, but I guess we're stuck with it. I wonder if the type assertion has outlived its usefulness? I.e. drop the `T == U` part and change the assertion to `assert count ==

[issue39218] Assertion failure when calling statistics.variance() on a float32 Numpy array

2020-01-04 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: I think it's more of an implementation artifact of numpy eq definition for float32 and float64 and can possibly break again if (x-c) * (x-c) was also changed to return float64 in future. -- nosy: +rhettinger, steven.daprano, taleinat,

[issue39218] Assertion failure when calling statistics.variance() on a float32 Numpy array

2020-01-04 Thread Reed
New submission from Reed : If a float32 Numpy array is passed to statistics.variance(), an assertion failure occurs. For example: import statistics import numpy as np x = np.array([1, 2], dtype=np.float32) statistics.variance(x) The assertion error is: assert T == U

Re: numpy array - convert hex to int

2019-09-10 Thread Piet van Oostrum
Sharan Basappa writes: > On Sunday, 8 September 2019 11:16:52 UTC-4, Luciano Ramalho wrote: >> >>> int('C0FFEE', 16) >> 12648430 >> >> There you go! >> >> On Sun, Sep 8, 2019 at 12:02 PM Sharan Basappa >> wrote: >> > >>

Re: numpy array - convert hex to int

2019-09-09 Thread Sharan Basappa
On Sunday, 8 September 2019 11:16:52 UTC-4, Luciano Ramalho wrote: > >>> int('C0FFEE', 16) > 12648430 > > There you go! > > On Sun, Sep 8, 2019 at 12:02 PM Sharan Basappa > wrote: > > > > I have a numpy array that has data in the form of hex. >

Re: numpy array - convert hex to int

2019-09-08 Thread Luciano Ramalho
>>> int('C0FFEE', 16) 12648430 There you go! On Sun, Sep 8, 2019 at 12:02 PM Sharan Basappa wrote: > > I have a numpy array that has data in the form of hex. > I would like to convert that into decimal/integer. > Need suggestions please. > -- > https://mail.python.

numpy array - convert hex to int

2019-09-08 Thread Sharan Basappa
I have a numpy array that has data in the form of hex. I would like to convert that into decimal/integer. Need suggestions please. -- https://mail.python.org/mailman/listinfo/python-list

Re: Numpy array

2018-05-21 Thread Rob Gaddi
On 05/18/2018 09:50 PM, Sharan Basappa wrote: This is regarding numpy array. I am a bit confused how parts of the array are being accessed in the example below. 1 import scipy as sp 2 data = sp.genfromtxt("web_traffic.tsv", delimiter="\t") 3 print(data[:10]) 4 x = data

Re: Numpy array

2018-05-20 Thread Gary Herron
The "indexing" page of the documentation might help you with this: https://docs.scipy.org/doc/numpy-1.14.0/reference/arrays.indexing.html On 05/18/2018 09:50 PM, sharan.basa...@gmail.com wrote: This is regarding numpy array. I am a bit confused how parts of the array are bein

Numpy array

2018-05-18 Thread Sharan Basappa
This is regarding numpy array. I am a bit confused how parts of the array are being accessed in the example below. 1 import scipy as sp 2 data = sp.genfromtxt("web_traffic.tsv", delimiter="\t") 3 print(data[:10]) 4 x = data[:,0] 5 y = data[:,1] Apparently, line 3 prints

[issue28302] Unpacking numpy array give list

2016-09-28 Thread R. David Murray
R. David Murray added the comment: Yes, you are unpacking into a list, that's what the * syntax does in this context. Since the rhs can be a mix of types, there's really no other reasonable meaning for the syntax. (The same is true for tuples, by the way). -- components: +Regular

[issue28302] Unpacking numpy array give list

2016-09-28 Thread SilentGhost
SilentGhost added the comment: It doesn't matter what you're unpacking, *y will collect the unpacked elements into a list. -- components: +Interpreter Core -Regular Expressions nosy: +SilentGhost resolution: -> not a bug stage: -> resolved status: open -> closed

[issue28302] Unpacking numpy array give list

2016-09-28 Thread RAMESH PAMPANA
New submission from RAMESH PAMPANA: Unpacking numpy array gives list rather numpy array. >>> import numpy as np >>> a = np.array([1,2,3,4]) >>> x, *y, z = a >>> type(a) >>> type(y) > >> type(x) -- components: Regular Expre

Re: fastest way to read a text file in to a numpy array

2016-06-30 Thread Christian Gollwitzer
Am 30.06.16 um 17:49 schrieb Heli: Dear all, After a few tests, I think I will need to correct a bit my question. I will give an example here. I have file 1 with 250 lines: X1,Y1,Z1 X2,Y2,Z2 Then I have file 2 with 3M lines: X1,Y1,Z1,value11,value12, value13,

Re: fastest way to read a text file in to a numpy array

2016-06-30 Thread Heli
Dear all, After a few tests, I think I will need to correct a bit my question. I will give an example here. I have file 1 with 250 lines: X1,Y1,Z1 X2,Y2,Z2 Then I have file 2 with 3M lines: X1,Y1,Z1,value11,value12, value13, X2,Y2,Z2,value21,value22, value23,... I will need to

Re: fastest way to read a text file in to a numpy array

2016-06-28 Thread Cody Piersall
On Tue, Jun 28, 2016 at 8:45 AM, Heli <heml...@gmail.com> wrote: > Hi, > > I need to read a file in to a 2d numpy array containing many number of lines. > I was wondering what is the fastest way to do this? > > Is even reading the file in to numpy array the best metho

Re: fastest way to read a text file in to a numpy array

2016-06-28 Thread Michael Selik
On Tue, Jun 28, 2016 at 10:08 AM Hedieh Ebrahimi wrote: > File 1 has : > x1,y1,z1 > x2,y2,z2 > > > and file2 has : > x1,y1,z1,value1 > x2,y2,z2,value2 > x3,y3,z3,value3 > ... > > I need to read the coordinates from file 1 and then interpolate a value > for these

Re: fastest way to read a text file in to a numpy array

2016-06-28 Thread Michael Selik
On Tue, Jun 28, 2016 at 9:51 AM Heli <heml...@gmail.com> wrote: > Is even reading the file in to numpy array the best method or there are > better approaches? > What are you trying to accomplish? Summary statistics, data transformation, analysis...? -- https://mail.python.org/m

fastest way to read a text file in to a numpy array

2016-06-28 Thread Heli
Hi, I need to read a file in to a 2d numpy array containing many number of lines. I was wondering what is the fastest way to do this? Is even reading the file in to numpy array the best method or there are better approaches? Thanks for your suggestions, -- https://mail.python.org/mailman

Re: looping and searching in numpy array

2016-03-14 Thread Oscar Benjamin
On 10 March 2016 at 13:02, Peter Otten <__pete...@web.de> wrote: > Heli wrote: > >> I need to loop over a numpy array and then do the following search. The >> following is taking almost 60(s) for an array (npArray1 and npArray2 in >> the example below) with aroun

Re: looping and searching in numpy array

2016-03-13 Thread srinivas devaki
tnoteight On Mar 10, 2016 5:15 PM, "Heli" <heml...@gmail.com> wrote: Dear all, I need to loop over a numpy array and then do the following search. The following is taking almost 60(s) for an array (npArray1 and npArray2 in the example below) with around 300K values. for

RE: looping and searching in numpy array

2016-03-13 Thread Albert-Jan Roskam
> From: sjeik_ap...@hotmail.com > To: heml...@gmail.com; python-list@python.org > Subject: RE: looping and searching in numpy array > Date: Sun, 13 Mar 2016 13:51:23 + > > Hi, I suppose you have seen this already (in particular the first link): > http://nump

RE: looping and searching in numpy array

2016-03-13 Thread Albert-Jan Roskam
> Date: Thu, 10 Mar 2016 08:48:48 -0800 > Subject: Re: looping and searching in numpy array > From: heml...@gmail.com > To: python-list@python.org > > On Thursday, March 10, 2016 at 2:02:57 PM UTC+1, Peter Otten wrote: > > Heli wrote: > > > > > Dea

Re: looping and searching in numpy array

2016-03-10 Thread Heli
On Thursday, March 10, 2016 at 5:49:07 PM UTC+1, Heli wrote: > On Thursday, March 10, 2016 at 2:02:57 PM UTC+1, Peter Otten wrote: > > Heli wrote: > > > > > Dear all, > > > > > > I need to loop over a numpy array and then do the following search.

Re: looping and searching in numpy array

2016-03-10 Thread Heli
On Thursday, March 10, 2016 at 2:02:57 PM UTC+1, Peter Otten wrote: > Heli wrote: > > > Dear all, > > > > I need to loop over a numpy array and then do the following search. The > > following is taking almost 60(s) for an array (npArray1 and npArray2 in > >

Re: looping and searching in numpy array

2016-03-10 Thread Mark Lawrence
On 10/03/2016 11:43, Heli wrote: Dear all, I need to loop over a numpy array and then do the following search. The following is taking almost 60(s) for an array (npArray1 and npArray2 in the example below) with around 300K values. for id in np.nditer(npArray1): newId=(np.where

Re: looping and searching in numpy array

2016-03-10 Thread Peter Otten
Heli wrote: > Dear all, > > I need to loop over a numpy array and then do the following search. The > following is taking almost 60(s) for an array (npArray1 and npArray2 in > the example below) with around 300K values. > > > for id in np.nditer(npArray1): >

looping and searching in numpy array

2016-03-10 Thread Heli
Dear all, I need to loop over a numpy array and then do the following search. The following is taking almost 60(s) for an array (npArray1 and npArray2 in the example below) with around 300K values. for id in np.nditer(npArray1): newId=(np.where(npArray2==id))[0][0

3D numpy array subset

2015-12-09 Thread Heli
Dear all, I am reading a dataset from a HDF5 file using h5py. my datasets are 3D. Then I will need to check if another 3d numpy array is a subset of this 3D array i am reading from the file. In general, is there any way to check if two 3d numpy arrays have intersections and if so, get

Re: 3D numpy array subset

2015-12-09 Thread Oscar Benjamin
On 9 Dec 2015 14:26, "Heli" <heml...@gmail.com> wrote: > > Dear all, > > I am reading a dataset from a HDF5 file using h5py. my datasets are 3D. > > Then I will need to check if another 3d numpy array is a subset of this 3D array i am reading from the file

Re: Fast capture and 2D image stacking as 3D numpy array with Python and Raspberry Pi

2015-07-07 Thread Mark Lawrence
array using numpy array, without saving each 2D capture as a file (because is slow). I found this Python code to take images as fast as possible, but i don't know how to stack all images fast to a 3D stack of images. import io import time import picamera #from PIL import Image def outputs

Re: Fast capture and 2D image stacking as 3D numpy array with Python and Raspberry Pi

2015-07-07 Thread Oscar Benjamin
On Mon, 6 Jul 2015 at 22:36 Agustin Cruz agustin.c...@gmail.com wrote: I'm working on a Python - Raspberry Pi project in which I need to take about 30 images per second (no movie) and stack each 2D image to a 3D array using numpy array, without saving each 2D capture as a file (because

Re: Fast capture and 2D image stacking as 3D numpy array with Python and Raspberry Pi

2015-07-06 Thread Agustin Cruz
On Monday, July 6, 2015 at 6:00:42 PM UTC-4, Mark Lawrence wrote: On 06/07/2015 22:31, Agustin Cruz wrote: I'm working on a Python - Raspberry Pi project in which I need to take about 30 images per second (no movie) and stack each 2D image to a 3D array using numpy array, without saving

Re: Fast capture and 2D image stacking as 3D numpy array with Python and Raspberry Pi

2015-07-06 Thread Mark Lawrence
On 06/07/2015 22:31, Agustin Cruz wrote: I'm working on a Python - Raspberry Pi project in which I need to take about 30 images per second (no movie) and stack each 2D image to a 3D array using numpy array, without saving each 2D capture as a file (because is slow). I found this Python code

Fast capture and 2D image stacking as 3D numpy array with Python and Raspberry Pi

2015-07-06 Thread Agustin Cruz
I'm working on a Python - Raspberry Pi project in which I need to take about 30 images per second (no movie) and stack each 2D image to a 3D array using numpy array, without saving each 2D capture as a file (because is slow). I found this Python code to take images as fast as possible, but i

numpy array product driving me mad

2015-03-20 Thread Mr. Twister
Hi everyone. Hope you can help me overcome this noob issue. I have two numpy arrays: P array([[[ 2, 3], [33, 44], [22, 11], [ 1, 2]]]) R array([0, 1, 2, 3]) the values of these may of course be different. The important fact is that: P.shape (1, 4, 2) R.shape (4,)

Re: numpy array product driving me mad

2015-03-20 Thread Manolo Martínez
On 03/20/15 at 01:46pm, Mr. Twister wrote: I have two numpy arrays: P array([[[ 2, 3], [33, 44], [22, 11], [ 1, 2]]]) R array([0, 1, 2, 3]) the values of these may of course be different. The important fact is that: P.shape (1, 4, 2) R.shape (4,)

Re: numpy array product driving me mad

2015-03-20 Thread Manolo Martínez
On 03/20/15 at 02:11pm, Manolo Martínez wrote: On 03/20/15 at 01:46pm, Mr. Twister wrote: I have two numpy arrays: [...] Is there a direct, single expression command to get this result? I think that you want P * R[;,None] Sorry, I meant P * R[:, None] Manolo --

Re: numpy array product driving me mad

2015-03-20 Thread Mr. Twister
I think that you want P * R[;,None] Sorry, I meant P * R[:, None] Manolo Muchísimas gracias, Manolo. Eres un genio y me has ayudado mucho. Te debo una. -- https://mail.python.org/mailman/listinfo/python-list

Extract Indices of Numpy Array Based on Given Bit Information

2014-10-18 Thread Artur Bercik
Dear Python and Numpy Users: My data are in the form of '32-bit unsigned integer' as follows: myData = np.array([1073741824, 1073741877, 1073742657, 1073742709, 1073742723, 1073755137, 1073755189,1073755969],dtype=np.int32) I want to get the index of my data where the following occurs: Bit No.

Re: Extract Indices of Numpy Array Based on Given Bit Information

2014-10-18 Thread Chris Angelico
On Sat, Oct 18, 2014 at 4:58 PM, Artur Bercik vbubbl...@gmail.com wrote: I want to get the index of my data where the following occurs: Bit No. 0–1 Bit Combination: 00 So, what you want to do is look at each number in binary, and find the ones that have two zeroes in the last two places?

Re: Extract Indices of Numpy Array Based on Given Bit Information

2014-10-18 Thread Chris Angelico
On Sat, Oct 18, 2014 at 5:42 PM, Artur Bercik vbubbl...@gmail.com wrote: I got some sense, but could not imagine if required Bit No. 2–5, and Bit Combination . I hope example with the new case would make me more sense. Just write the number in binary, with the bits you're interested in

Re: Extract Indices of Numpy Array Based on Given Bit Information

2014-10-18 Thread Chris Angelico
On Sat, Oct 18, 2014 at 6:02 PM, Artur Bercik vbubbl...@gmail.com wrote: So, the Bit No. 2-5 for the following case is '1101', right? 1073741877: 1110101 If my required bit combination for Bit No. 2-5 is '1011', then the above number (1073741877) is not chosen,

Re: Extract Indices of Numpy Array Based on Given Bit Information

2014-10-18 Thread Chris Angelico
On Sat, Oct 18, 2014 at 6:21 PM, Artur Bercik vbubbl...@gmail.com wrote: Thank you very much Chris Angelico, I have come to know it. You're most welcome. And thank you for taking heed of the request to not top-post. :) Hang around, you never know what weird and wonderful things you'll learn! --

Re: Extract Indices of Numpy Array Based on Given Bit Information

2014-10-18 Thread Artur Bercik
So, the Bit No. 2-5 for the following case is '1101', right? 1073741877: 1110101 If my required bit combination for Bit No. 2-5 is '1011', then the above number (1073741877) is not chosen, right?? Look forward to know your confirmation. On Sat, Oct 18, 2014 at 3:50

Re: Extract Indices of Numpy Array Based on Given Bit Information

2014-10-18 Thread Artur Bercik
Thanks Chris Angelico for your nice answer. I got some sense, but could not imagine if required Bit No. 2–5, and Bit Combination . I hope example with the new case would make me more sense. Artur On Sat, Oct 18, 2014 at 3:24 PM, Chris Angelico ros...@gmail.com wrote: On Sat, Oct 18,

Re: Extract Indices of Numpy Array Based on Given Bit Information

2014-10-18 Thread Artur Bercik
On Sat, Oct 18, 2014 at 4:10 PM, Chris Angelico ros...@gmail.com wrote: On Sat, Oct 18, 2014 at 6:02 PM, Artur Bercik vbubbl...@gmail.com wrote: So, the Bit No. 2-5 for the following case is '1101', right? 1073741877: 1110101 If my required bit combination for

Re: [SciPy-User] Convert 3d NumPy array into 2d

2014-08-27 Thread Maximilian Albert
[source] http://github.com/numpy/numpy/blob/v1.8.1/numpy/core/fromnumeric.py#L1072 http://docs.scipy.org/doc/numpy/reference/generated/numpy.squeeze.html#numpy.squeeze 2014-08-27 16:08 GMT+01:00 phinn stuart dphinnstu...@gmail.com: Hi everyone, how can I convert (1L, 480L, 1440L) shaped numpy

Convert 3d NumPy array into 2d

2014-08-27 Thread phinn stuart
Hi everyone, how can I convert (1L, 480L, 1440L) shaped numpy array into (480L, 1440L)? Thanks in the advance. phinn -- https://mail.python.org/mailman/listinfo/python-list

Re: Convert 3d NumPy array into 2d

2014-08-27 Thread Gary Herron
On 08/27/2014 08:08 AM, phinn stuart wrote: Hi everyone, how can I convert (1L, 480L, 1440L) shaped numpy array into (480L, 1440L)? Thanks in the advance. phinn A simple assignment into the arrays shape does it: a = numpy.zeros((1,480,1440)) a.shape (1, 480, 1440) a.shape = (480,1440

Announcement - Learning NumPy Array

2014-06-30 Thread Priyanka Budkuley
Hi, I am pleased to inform you about the Publication of Learning NumPy Array http://bit.ly/UyKBJ1 by Ivan Idris. This book is a step-by-step guide which gives a comprehensive overview of Nympy. Now that the book is published, I am looking for people who can review our new title

Re: Numpy Array of Sets

2014-05-25 Thread LJ
Wolfgang, thank you very much for your reply. Following the example in the link, the problem appears: A = [[0]*2]*3 A [[0, 0], [0, 0], [0, 0]] A[0][0] = 5 A [[5, 0], [5, 0], [5, 0]] Now, if I use a numpy array: d=array([[0]*2]*3) d array([[0, 0], [0, 0], [0, 0]]) d[0][0]=5

Re: Numpy Array of Sets

2014-05-25 Thread Peter Otten
of the value shows in all six entries. Likewise if you change the `inner` list the modification shows in all three rows. A [[0, 0], [0, 0], [0, 0]] A[0][0] = 5 A [[5, 0], [5, 0], [5, 0]] Now, if I use a numpy array: d=array([[0]*2]*3) d array([[0, 0], [0, 0], [0, 0

Re: Numpy Array of Sets

2014-05-25 Thread LJ
Thank you for the reply. So, as long as I access and modify the elements of, for example, A=array([[set([])]*4]*3) as (for example): a[0][1] = a[0][1] | set([1,2]) or: a[0][1]=set([1,2]) then I should have no problems? -- https://mail.python.org/mailman/listinfo/python-list

Re: Numpy Array of Sets

2014-05-25 Thread Peter Otten
LJ wrote: Thank you for the reply. So, as long as I access and modify the elements of, for example, A=array([[set([])]*4]*3) as (for example): a[0][1] = a[0][1] | set([1,2]) or: a[0][1]=set([1,2]) then I should have no problems? As long as you set (i. e. replace) elements

Re: Numpy Array of Sets

2014-05-25 Thread LJ
Thank you very much! -- https://mail.python.org/mailman/listinfo/python-list

Numpy Array of Sets

2014-05-24 Thread Luis José Novoa
Hi All, Hope you're doing great. One quick question. I am defining an array of sets using numpy as: a=array([set([])]*3) Now, if I want to add an element to the set in, lets say, a[0], and I use the .add(4) operation, which results in: array([set([4]), set([4]), set([4])], dtype=object)

Re: Numpy Array of Sets

2014-05-24 Thread Robert Kern
On 2014-05-24 23:05, Luis José Novoa wrote: Hi All, Hope you're doing great. One quick question. I am defining an array of sets using numpy as: a=array([set([])]*3) Now, if I want to add an element to the set in, lets say, a[0], and I use the .add(4) operation, which results in:

Re: Numpy Array of Sets

2014-05-24 Thread Wolfgang Maier
On 25.05.2014 00:14, Robert Kern wrote: On 2014-05-24 23:05, Luis José Novoa wrote: Hi All, Hope you're doing great. One quick question. I am defining an array of sets using numpy as: a=array([set([])]*3) Has nothing to do with numpy, but the problem is exclusively with your innermost

Re: Convert numpy array to single number

2014-05-01 Thread Papp Győző
Maybe something like this? to_num = lambda array: np.sum(array * 2**np.arange(len(array)-1, -1, -1)) to_num(np.array([1,0,1,0])) 10 2014-04-29 17:42 GMT+02:00 Tom P werot...@freent.dd: On 28.04.2014 15:04, mboyd02...@gmail.com wrote: I have a numpy array consisting of 1s and zeros

Re: Convert numpy array to single number

2014-04-29 Thread Tom P
On 28.04.2014 15:04, mboyd02...@gmail.com wrote: I have a numpy array consisting of 1s and zeros for representing binary numbers: e.g. binary array([ 1., 0., 1., 0.]) I wish the array to be in the form 1010, so it can be manipulated. I do not want to use built in binary

Convert numpy array to single number

2014-04-28 Thread mboyd02255
I have a numpy array consisting of 1s and zeros for representing binary numbers: e.g. binary array([ 1., 0., 1., 0.]) I wish the array to be in the form 1010, so it can be manipulated. I do not want to use built in binary converters as I am trying to build my own. -- https

Re: Convert numpy array to single number

2014-04-28 Thread Steven D'Aprano
On Mon, 28 Apr 2014 06:04:02 -0700, mboyd02255 wrote: I have a numpy array consisting of 1s and zeros for representing binary numbers: e.g. binary array([ 1., 0., 1., 0.]) I wish the array to be in the form 1010, so it can be manipulated. I do not want to use built

Re:Convert numpy array to single number

2014-04-28 Thread Dave Angel
mboyd02...@gmail.com Wrote in message: I have a numpy array consisting of 1s and zeros for representing binary numbers: e.g. binary array([ 1., 0., 1., 0.]) I wish the array to be in the form 1010, so it can be manipulated. I do not want to use built in binary

numpy array operation

2013-01-29 Thread C. Ng
Is there a numpy operation that does the following to the array? 1 2 == 4 3 3 4 2 1 Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list

Re: numpy array operation

2013-01-29 Thread Peter Otten
C. Ng wrote: Is there a numpy operation that does the following to the array? 1 2 == 4 3 3 4 2 1 How about a array([[1, 2], [3, 4]]) a[::-1].transpose()[::-1].transpose() array([[4, 3], [2, 1]]) Or did you mean a.reshape((4,))[::-1].reshape((2,2)) array([[4, 3],

Re: numpy array operation

2013-01-29 Thread Tim Williams
On Tuesday, January 29, 2013 3:41:54 AM UTC-5, C. Ng wrote: Is there a numpy operation that does the following to the array? 1 2 == 4 3 3 4 2 1 Thanks in advance. import numpy as np a=np.array([[1,2],[3,4]]) a array([[1, 2], [3, 4]]) np.fliplr(np.flipud(a))

Re: numpy array operation

2013-01-29 Thread Alok Singhal
On Tue, 29 Jan 2013 00:41:54 -0800, C. Ng wrote: Is there a numpy operation that does the following to the array? 1 2 == 4 3 3 4 2 1 Thanks in advance. How about: import numpy as np a = np.array([[1,2],[3,4]]) a array([[1, 2], [3, 4]]) a[::-1, ::-1] array([[4, 3],

Re: numpy array operation

2013-01-29 Thread Terry Reedy
On 1/29/2013 1:49 PM, Alok Singhal wrote: On Tue, 29 Jan 2013 00:41:54 -0800, C. Ng wrote: Is there a numpy operation that does the following to the array? 1 2 == 4 3 3 4 2 1 Thanks in advance. How about: import numpy as np a = np.array([[1,2],[3,4]]) a array([[1, 2], [3, 4]])

Re: splitting numpy array unevenly

2012-09-19 Thread Hans Mulder
On 18/09/12 16:02:02, Wanderer wrote: On Monday, September 17, 2012 7:43:06 PM UTC-4, Martin De Kauwe wrote: On Tuesday, September 18, 2012 8:31:09 AM UTC+10, Wanderer wrote: I need to divide a 512x512 image array with the first horizontal and vertical division 49 pixels in. Then every 59

Re: splitting numpy array unevenly

2012-09-18 Thread Wanderer
On Monday, September 17, 2012 7:43:06 PM UTC-4, Martin De Kauwe wrote: On Tuesday, September 18, 2012 8:31:09 AM UTC+10, Wanderer wrote: I need to divide a 512x512 image array with the first horizontal and vertical division 49 pixels in. Then every 59 pixels in after that. hsplit and

splitting numpy array unevenly

2012-09-17 Thread Wanderer
I need to divide a 512x512 image array with the first horizontal and vertical division 49 pixels in. Then every 59 pixels in after that. hsplit and vsplit want to start at the edges and create a bunch of same size arrays. Is there a command to chop off different sized arrays? Thanks --

Re: splitting numpy array unevenly

2012-09-17 Thread Martin De Kauwe
On Tuesday, September 18, 2012 8:31:09 AM UTC+10, Wanderer wrote: I need to divide a 512x512 image array with the first horizontal and vertical division 49 pixels in. Then every 59 pixels in after that. hsplit and vsplit want to start at the edges and create a bunch of same size arrays. Is

Re: splitting numpy array unevenly

2012-09-17 Thread Joshua Landau
On 17 September 2012 23:31, Wanderer wande...@dialup4less.com wrote: I need to divide a 512x512 image array with the first horizontal and vertical division 49 pixels in. Then every 59 pixels in after that. hsplit and vsplit want to start at the edges and create a bunch of same size arrays. Is

Convert ctypes 16 bit c_short array to a 32 bit numpy array

2011-03-24 Thread Wanderer
I'm using ctypes to have a dll fill a buffer with 16 bit data. I then want to convert this data to a numpy array. The code snippet below converts the data from 16 bit to 32 bit, but two 16 bit numbers are concatenated to make a 32 bit number and half the array is zero. Buffer = (c_short

Re: Convert ctypes 16 bit c_short array to a 32 bit numpy array

2011-03-24 Thread Wanderer
On Mar 24, 3:14 pm, Wanderer wande...@dialup4less.com wrote: I'm using ctypes to have a dll fill a buffer with 16 bit data. I then want to convert this data to a numpy array. The code snippet below converts the data from 16 bit to 32 bit, but two 16 bit numbers are concatenated to make a 32

Re: Reading bz2 file into numpy array

2010-11-23 Thread Peter Otten
Nobody wrote: On Mon, 22 Nov 2010 11:37:22 +0100, Peter Otten wrote: is there a convenient way to read bz2 files into a numpy array? Try f = bz2.BZ2File(filename) data = numpy.fromstring(f.read(), numpy.float32) That's going to hurt if the file is large. Yes, but memory usage

Reading bz2 file into numpy array

2010-11-22 Thread Johannes Korn
Hi, is there a convenient way to read bz2 files into a numpy array? I tried: from bz2 import * from numpy import * fd = BZ2File(filename, 'rb') read_data = fromfile(fd, float32) but BZ2File doesn't seem to produce a transparent filehandle. Kind regards! Johannes -- http://mail.python.org

Re: Reading bz2 file into numpy array

2010-11-22 Thread Peter Otten
Johannes Korn wrote: I tried: from bz2 import * from numpy import * fd = BZ2File(filename, 'rb') read_data = fromfile(fd, float32) but BZ2File doesn't seem to produce a transparent filehandle. is there a convenient way to read bz2 files into a numpy array? Try import numpy import

  1   2   >