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 is

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'

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 thou

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

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

2020-11-25 Thread pjfarley3
py --- > -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

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 value

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 t

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

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 o

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://ma

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 being a

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 the

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, X2,Y2,Z2,value21,value22

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 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 method or there are &

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 coordinates on file 2 to the

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 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/mailman/listinfo/python-list

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 around 3

Re: looping and searching in numpy array

2016-03-13 Thread srinivas devaki
_id: @eightnoteight On Mar 10, 2016 5:15 PM, "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(npArr

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: > > > > > Dear

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. The >

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

Re: 3D numpy array subset

2015-12-09 Thread Oscar Benjamin
On 9 Dec 2015 14:26, "Heli" 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. > > In general, is ther

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 the

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 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 > s

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

2015-07-06 Thread Mark Lawrence
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 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 d

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 > >

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

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,

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

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 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,

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) >>>

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 wrote: > On Sat, Oct 18, 2014 at 6:02 PM, Artur Bercik 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', t

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 PM,

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 wrote: > On Sat, Oct 18, 2014 at 4:58 PM, A

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 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! -- https://mail.pyt

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 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, right?? > > Look f

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

2014-10-17 Thread Chris Angelico
On Sat, Oct 18, 2014 at 5:42 PM, Artur Bercik 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 set to 1, and e

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

2014-10-17 Thread Chris Angelico
On Sat, Oct 18, 2014 at 4:58 PM, Artur Bercik 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? 1073741824: 1000

Extract Indices of Numpy Array Based on Given Bit Information

2014-10-17 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: 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,

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: [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 : > Hi everyone, how can I convert (1L, 480L, 1440L) shaped numpy arr

Re: Numpy Array of Sets

2014-05-25 Thread LJ
Thank you very much! -- 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. re

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
ike your original set) a modification 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,

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

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 expr

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: array([set(

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) whi

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 : > On 28.04.2014 15:04, mboyd02...@gmail.com wrote: > >> I have a numpy array

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

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

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 ca

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.

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: 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]

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.

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)) ar

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: splitting numpy array unevenly

2012-09-18 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

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 > >

Re: splitting numpy array unevenly

2012-09-17 Thread Joshua Landau
On 17 September 2012 23:31, 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 there a command to c

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

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 -- http://

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 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 bi

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_

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

Re: Reading bz2 file into numpy array

2010-11-22 Thread Nobody
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. You might be bette

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 fi

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://

Re: Multiprocessing.Array bug / shared numpy array

2009-10-08 Thread Robert Kern
On 2009-10-08 15:14 PM, Felix wrote: I am trying to create a shared, read-only numpy.ndarray between several processes. After some googling the basic idea is: sarr = mp.Array('i',1000) ndarr = scipy.frombuffer(sarr._obj,dtype='int32') Since it will be read only (after being filled once in a si

Multiprocessing.Array bug / shared numpy array

2009-10-08 Thread Felix
Hi, The documentation for the Multiprocessing.Array says: multiprocessing.Array(typecode_or_type, size_or_initializer, *, lock=True)¶ ... If lock is False then access to the returned object will not be automatically protected by a lock, so it will not necessarily be “process-safe”. ... However:

Re: numpy array merge

2009-08-10 Thread Robert Kern
On 2009-08-10 17:38, Nathan wrote: Is there an easy way to merge two numpy arrays with different rank sizes (terminology?). You will want to ask numpy questions on the numpy mailing list. http://www.scipy.org/Mailing_Lists I believe that "shape" is the term you are looking for. I want to

numpy array merge

2009-08-10 Thread Nathan
Is there an easy way to merge two numpy arrays with different rank sizes (terminology?). I want to make a single array by concatenating two arrays along a given direction and filling the excess cells with a dummy variable. numpy concatenate works well as long as the two arrays have the same dimen

Re: clean way prepend an element to a numpy array

2009-07-24 Thread Robert Kern
On 2009-07-24 18:26, greg wrote: Robert Kern wrote: a[:0] = array('i', [0]) Not when 'a' is a numpy array rather than an array.array. That's true, but I got the impression that the OP was talking about array.array, not numpy.array. Did you read the Subject: line

Re: clean way prepend an element to a numpy array

2009-07-24 Thread greg
Robert Kern wrote: a[:0] = array('i', [0]) Not when 'a' is a numpy array rather than an array.array. That's true, but I got the impression that the OP was talking about array.array, not numpy.array. It's very confusing having two widely-used types both called

Re: clean way prepend an element to a numpy array

2009-07-22 Thread Robert Kern
On 2009-07-22 01:51, greg wrote: bdb112 wrote: I saw this interest syntax on this site x[:0]=0 I guess that is cute, but could be confusing(and doesn't work) It does if you use an array of the appropriate type on the right hand side: a[:0] = array('i', [0]) Not when

Re: clean way prepend an element to a numpy array

2009-07-21 Thread greg
bdb112 wrote: I saw this interest syntax on this site x[:0]=0 I guess that is cute, but could be confusing(and doesn't work) It does if you use an array of the appropriate type on the right hand side: a[:0] = array('i', [0]) -- Greg -- http://mail.python.org/mailman/listinfo/python-li

Re: clean way prepend an element to a numpy array

2009-07-21 Thread Robert Kern
On 2009-07-20 22:56, bdb112 wrote: If I want to add an element at the beginning of an array, it seems like I must make a list, insert in place, then make an array again. the_array = numpy.concatenate([new_value, the_array]) You will want to ask numpy questions on the numpy mailing list. htt

Re: clean way prepend an element to a numpy array

2009-07-20 Thread bdb112
On Jul 21, 2:13 pm, Ben Finney wrote: > bdb112 writes: > > If I want to add an element at the beginning of an array, it seems > > like I must make a list, insert in place, then make an array again. > > The NumPy ‘ndarray’ type (which is what you get by default from the > ‘array’ factory function)

Re: clean way prepend an element to a numpy array

2009-07-20 Thread Ben Finney
bdb112 writes: > If I want to add an element at the beginning of an array, it seems > like I must make a list, insert in place, then make an array again. The NumPy ‘ndarray’ type (which is what you get by default from the ‘array’ factory function) is a far more complex type than (and is not deri

clean way prepend an element to a numpy array

2009-07-20 Thread bdb112
If I want to add an element at the beginning of an array, it seems like I must make a list, insert in place, then make an array again. Of course, lists can be efficient too, and the insert() funtion works nicely in that case, but sometimes arrays are the best choice e.g. x=array([1,2,3]) # to put

Re: deleting certain entries in numpy array

2009-07-02 Thread Robert Kern
On 2009-07-02 04:40, Sebastian Schabe wrote: Robert Kern schrieb: > You will want to ask numpy questions on the numpy mailing list. > > http://www.scipy.org/Mailing_Lists > I ever thought news-groups are the right way for questions like this. And the mailing list page just confuses me, bu

Re: deleting certain entries in numpy array

2009-07-02 Thread Sebastian Schabe
Robert Kern schrieb: First, convert the pos array to integers, and just the columns with indices in them: ipos = pos[:,:2].astype(int) Now check the values in the mask corresponding to these positions: mask_values = mask[ipos[:,0], ipos[:,1]] Now extract the rows from the original pos ar

Re: deleting certain entries in numpy array

2009-07-01 Thread Robert Kern
On 2009-07-01 09:51, Sebastian Schabe wrote: Hello everybody, I'm new to python and numpy and have a little/special problem: You will want to ask numpy questions on the numpy mailing list. http://www.scipy.org/Mailing_Lists I have an numpy array which is in fact a gray scale image

Re: deleting certain entries in numpy array

2009-07-01 Thread Ben Finney
Sebastian Schabe writes: > I want to avoid a for loop (if possible!!!) cause I think (but don't > know) numpy array are handled in another way. Yes, Numpy arrays can be indexed logically by a boolean array. > I think numpy.delete is the right function for discarding the values,

deleting certain entries in numpy array

2009-07-01 Thread Sebastian Schabe
Hello everybody, I'm new to python and numpy and have a little/special problem: I have an numpy array which is in fact a gray scale image mask, e.g.: mask = array([[ 0, 0, 0, 0, 0, 0, 0, 0, 0], [ 0, 0, 0, 0, 0, 0, 0, 0, 0], [ 0, 0, 0

Re: numpy array sorting weirdness

2009-03-29 Thread Daniel Fetchinson
>> Is there any reason the 'axis' keyword argument doesn't default to the >> value that corresponds to python list behaviour? That would make lot >> of sense I think. Or retaining compatibility with python lists is not >> really a goal of numpy.array? > > Not at all. It's an entirely different data

  1   2   >