Re: Byte arrays and DLLs

2022-07-03 Thread Rob Cliffe via Python-list
That worked.  Many thanks Eryk. Rob On 30/06/2022 23:45, Eryk Sun wrote: On 6/30/22, Rob Cliffe via Python-list wrote: AKAIK it is not possible to give ctypes a bytearray object and persuade it to give you a pointer to the actual array data, suitable for passing to a DLL. You're overlooking t

Re: Byte arrays and DLLs

2022-07-02 Thread Edmondo Giovannozzi
Il giorno venerdì 1 luglio 2022 alle 00:46:13 UTC+2 ery...@gmail.com ha scritto: > On 6/30/22, Rob Cliffe via Python-list wrote: > > > > AKAIK it is not possible to give ctypes a bytearray object and persuade > > it to give you a pointer to the actual array data, suitable for passing > > to a

Re: Byte arrays and DLLs

2022-06-30 Thread Eryk Sun
On 6/30/22, Rob Cliffe via Python-list wrote: > > AKAIK it is not possible to give ctypes a bytearray object and persuade > it to give you a pointer to the actual array data, suitable for passing > to a DLL. You're overlooking the from_buffer() method. For example: >>> ba = bytearray(10)

Byte arrays and DLLs

2022-06-30 Thread Rob Cliffe via Python-list
I have an application in which I wanted a fixed-length "array of bytes" (that's intended as an informal term) where I could read and write individual bytes and slices, and also pass the array to a DLL (one I wrote in C) which expects an "unsigned char *" parameter. I am using ctypes to talk to t

Re: ValueError: arrays must all be same length

2020-10-05 Thread Tim Williams
v/pandas/issues > > On Sun, 4 Oct 2020 at 13:55, Tim Williams wrote: > >> On Sun, Oct 4, 2020 at 8:39 AM Tim Williams wrote: >> >> > >> > >> > On Fri, Oct 2, 2020 at 11:00 AM Shaozhong SHI >> > wrote: >> > >> >>

Re: ValueError: arrays must all be same length

2020-10-05 Thread Shaozhong SHI
> >> Hello, > >> > >> I got a json response from an API and tried to use pandas to put data > into > >> a dataframe. > >> > >> However, I kept getting this ValueError: arrays must all be same length. > >> > >> Can anyone he

Re: ValueError: arrays must all be same length

2020-10-04 Thread Tim Williams
On Sun, Oct 4, 2020 at 8:39 AM Tim Williams wrote: > > > On Fri, Oct 2, 2020 at 11:00 AM Shaozhong SHI > wrote: > >> Hello, >> >> I got a json response from an API and tried to use pandas to put data into >> a dataframe. >> >> However, I ke

Re: ValueError: arrays must all be same length

2020-10-04 Thread Tim Williams
On Fri, Oct 2, 2020 at 11:00 AM Shaozhong SHI wrote: > Hello, > > I got a json response from an API and tried to use pandas to put data into > a dataframe. > > However, I kept getting this ValueError: arrays must all be same length. > > Can anyone help? > >

Re: ValueError: arrays must all be same length

2020-10-04 Thread Christian Gollwitzer
Am 02.10.20 um 14:34 schrieb Shaozhong SHI: Hello, I got a json response from an API and tried to use pandas to put data into a dataframe. However, I kept getting this ValueError: arrays must all be same length. Can anyone help? The following is the json text. What do you expect the

Re: ValueError: arrays must all be same length

2020-10-03 Thread Peter Pearson
On Fri, 2 Oct 2020 13:34:46 +0100, Shaozhong SHI wrote: > Hello, > > I got a json response from an API and tried to use pandas to put data into > a dataframe. > > However, I kept getting this ValueError: arrays must all be same length. > > Can anyone help? > >

ValueError: arrays must all be same length

2020-10-02 Thread Shaozhong SHI
Hello, I got a json response from an API and tried to use pandas to put data into a dataframe. However, I kept getting this ValueError: arrays must all be same length. Can anyone help? The following is the json text. Regards, Shao { "locationId": "1-1004508435"

Appending to and removing from numpy arrays

2020-06-10 Thread Urs Thuermann
Hi, is it possible to append data to or remove data from numpy arrays like Python lists? I have some code where I currently use lists and often do things like a.append(elem) a += b del a[:-n] I am thinking of changing to numpy arrays but it seems I cannot modify numpy arrays like

How to create a boolean mask for the data arrays with uint16, int8 type?

2019-05-06 Thread blmadhavan
Hi, How can I create a boolean mask for the data arrays with integer type? I want to create a 'useSample' boolean array for masking or discarding the unwanted data from the array. [nr,nc] = np.shape(ftype) # useSamples = np.full((nr,nc), True, dtype=bool) I want to transform the

Re: write arrays to disk

2017-04-17 Thread Andre Müller
mpy.fromfile(fd, dtype=numpy.int) What you should not do: arr = [1, 2, 3, 4] with open('plain.txt', 'wt') as fd: fd.write(repr(arr)) with open('plain.txt') as fd: arr = eval(fd.read()) If you need to store more data, you should think about a database.

Re: write arrays to disk

2017-04-16 Thread Irmen de Jong
On 16-4-2017 14:28, jorge.conr...@cptec.inpe.br wrote: > Hi, > > I'm new on Python software. I would like to write on disk arrays in binary or > ascii > format. Can someone please help me? > > Thanks, > > Conrado What kind of data is in the arrays? Who or wha

write arrays to disk

2017-04-16 Thread jorge . conrado
Hi, I'm new on Python software. I would like to write on disk arrays in binary or ascii format. Can someone please help me? Thanks, Conrado -- https://mail.python.org/mailman/listinfo/python-list

Re: building numpy arrays with regular structure

2016-12-17 Thread Peter Otten
Seb wrote: > Is there an easier way to write a numpy array with a regular structure? > For example, an array with [0, 1] along the diagnal of one of the array > dimensions, and zero elsewhere: > > zz = np.array([[[0, 1], [0, 0], [0, 0]], >[[0, 0], [0, 1], [0, 0]], >

building numpy arrays with regular structure

2016-12-16 Thread Seb
Hello, Is there an easier way to write a numpy array with a regular structure? For example, an array with [0, 1] along the diagnal of one of the array dimensions, and zero elsewhere: zz = np.array([[[0, 1], [0, 0], [0, 0]], [[0, 0], [0, 1], [0, 0]], [[0, 0], [0, 0],

Re: Getting number of neighbours for a 3d numpy arrays

2016-07-12 Thread Nobody
Some common ways to handle the boundary condition: 1. Generate clamped indices, test for validity and substitute invalid entries with an "identity" element. E.g. ijk = np.mgrid[:a,:b,:c] i,j,k = ijk i0,j0,k0 = np.maximum(0,ijk-1) i1,j1,k1 = np.minimum(np.array(a,b,c).T-1,ijk+1) n1 = (i>

Re: Getting number of neighbours for a 3d numpy arrays

2016-07-12 Thread Peter Otten
Heli wrote: > I have a 3d numpy array containing true/false values for each i,j,k. The > size of the array is a*b*c. > > for each cell with indices i,j,k; I will need to check all its neighbours > and calculate the number of neighbour cells with true values. > > A cell with index i,j,k has the f

Getting number of neighbours for a 3d numpy arrays

2016-07-12 Thread Heli
there anyway I can get an array containg all n1 neighbour, a second array containing all n2 neighbours and so on and then add n1 to n6 arrays element-wise to get all neighbours that meet certain conditions for a cell. Thanks in Advance for your help, -- https://mail.python.org/mailman/listinfo/python-list

Re: Possible PEP - two dimensional arrays?

2016-06-08 Thread Michael Torrie
On 06/07/2016 06:17 PM, Harrison Chudleigh wrote: > I was programming a computer game and found that while 1D arrays can be > created using the module array, there is no module for two-dimensional > arrays, unlike languages like C. Currently, the closest thing Python has to > a 2

Re: Possible PEP - two dimensional arrays?

2016-06-08 Thread Terry Reedy
On 6/7/2016 8:17 PM, Harrison Chudleigh wrote: I was programming a computer game and found that while 1D arrays can be created using the module array, there is no module for two-dimensional arrays, unlike languages like C. Currently, the closest thing Python has to a 2D array is a dictionary

Re: Possible PEP - two dimensional arrays?

2016-06-07 Thread Rob Gaddi
Harrison Chudleigh wrote: > I was programming a computer game and found that while 1D arrays can be > created using the module array, there is no module for two-dimensional > arrays, unlike languages like C. Currently, the closest thing Python has to > a 2D array is a dictionary cont

Re: Possible PEP - two dimensional arrays?

2016-06-07 Thread Ned Batchelder
On Tuesday, June 7, 2016 at 8:19:33 PM UTC-4, Harrison Chudleigh wrote: > I was programming a computer game and found that while 1D arrays can be > created using the module array, there is no module for two-dimensional > arrays, unlike languages like C. Currently, the closest thing Pyth

Re: Possible PEP - two dimensional arrays?

2016-06-07 Thread Paul Rubin
Harrison Chudleigh writes: > Currently, the closest thing Python has to a 2D array is a dictionary > containing lists. Tuples work fine: d = {} d[2,3] = 5 # etc... > Is this idea PEPable? I don't think it would get any traction. If you're doing something numerical t

Possible PEP - two dimensional arrays?

2016-06-07 Thread Harrison Chudleigh
I was programming a computer game and found that while 1D arrays can be created using the module array, there is no module for two-dimensional arrays, unlike languages like C. Currently, the closest thing Python has to a 2D array is a dictionary containing lists. I propose that a module , 2DArray

Re: numpy arrays

2016-04-11 Thread Heli
As you said, this did the trick. sortedVal=np.array(val[ind]).reshape((xcoord.size,ycoord.size,zcoord.size)) Only val[ind] instead of val[ind,:] as val is 1D. Thanks Oscar, -- https://mail.python.org/mailman/listinfo/python-list

Re: numpy arrays

2016-04-11 Thread Heli
Thanks Oscar, In my case this did the trick. sortedVal=np.array(val[ind]).reshape((xcoord.size,ycoord.size,zcoord.size)) -- https://mail.python.org/mailman/listinfo/python-list

Re: numpy arrays

2016-04-07 Thread Oscar Benjamin
On 7 April 2016 at 15:31, Heli wrote: > > Thanks a lot Oscar, > > The lexsort you suggested was the way to go. Glad to hear it. > import h5py > import numpy as np > f=np.loadtxt(inputFile,delimiter=None) > xcoord=np.sort(np.unique(f[:,0])) > ycoord=np.sort(np.unique(f[:,1])) > zcoord=np.sort(np.

Re: numpy arrays

2016-04-07 Thread Heli
Thanks a lot Oscar, The lexsort you suggested was the way to go. import h5py import numpy as np f=np.loadtxt(inputFile,delimiter=None) xcoord=np.sort(np.unique(f[:,0])) ycoord=np.sort(np.unique(f[:,1])) zcoord=np.sort(np.unique(f[:,2])) x=f[:,0] y=f[:,1] z=f[:,2] val=f[:,3] ind = np.lexsort(

Re: numpy arrays

2016-04-07 Thread Oscar Benjamin
On 6 April 2016 at 17:26, Heli wrote: > > Thanks for your replies. I have a question in regard with my previous > question. I have a file that contains x,y,z and a value for that coordinate > on each line. Here I am giving an example of the file using a numpy array > called f. > > f=np.array([[

Re: numpy arrays

2016-04-06 Thread Heli
Thanks for your replies. I have a question in regard with my previous question. I have a file that contains x,y,z and a value for that coordinate on each line. Here I am giving an example of the file using a numpy array called f. f=np.array([[1,1,1,1], [1,1,2,2], [1,1,3

Re: numpy arrays

2016-03-23 Thread Nobody
> What you want is called *transposing* the array: > > http://docs.scipy.org/doc/numpy/reference/generated/numpy.transpose.html > > That should be a sufficiently fast operation. Transposing itself is fast, as it just swaps the strides and dimensions without touching the data (i.e. it returns a n

Re: numpy arrays

2016-03-23 Thread Simon Ward
On 23 March 2016 10:06:56 GMT+00:00, Heli wrote: >Hi, > >I have a 2D numpy array like this: > >[[1,2,3,4], > [1,2,3,4], > [1,2,3,4] > [1,2,3,4]] > >Is there any fast way to convert this array to > >[[1,1,1,1], > [2,2,2,2] > [3,3,3,3] > [4,4,4,4]] Use the transpose() method: http://docs.scipy

Re: numpy arrays

2016-03-23 Thread Heli
[3,3,3,3] > [4,4,4,4]] > > In general I would need to retrieve every nth element of the interior arrays > in to single arrays. I know I can loop over and do this, but I have really > big arrays and I need the fastest way to do this. > > Thanks for your help, Thanks a lot

Re: numpy arrays

2016-03-23 Thread Chris Angelico
On Wed, Mar 23, 2016 at 9:06 PM, Heli wrote: > I have a 2D numpy array like this: > > [[1,2,3,4], > [1,2,3,4], > [1,2,3,4] > [1,2,3,4]] > > Is there any fast way to convert this array to > > [[1,1,1,1], > [2,2,2,2] > [3,3,3,3] > [4,4,4,4]] What you want is called *transposing* the array: h

Re: numpy arrays

2016-03-23 Thread Manolo Martínez
;t mean just transposing your original array, as in original_array.T, right? > In general I would need to retrieve every nth element of the interior > arrays in to single arrays. I know I can loop over and do this, but I > have really big arrays and I need the fastest way to do this. I d

Re: numpy arrays

2016-03-23 Thread Steven D'Aprano
On Wed, 23 Mar 2016 09:06 pm, Heli wrote: > Hi, > > I have a 2D numpy array like this: > > [[1,2,3,4], > [1,2,3,4], > [1,2,3,4] > [1,2,3,4]] > > Is there any fast way to convert this array to > > [[1,1,1,1], > [2,2,2,2] > [3,3,3,3] > [4,4,4,4]] Mathematically, this is called the "tran

numpy arrays

2016-03-23 Thread Heli
Hi, I have a 2D numpy array like this: [[1,2,3,4], [1,2,3,4], [1,2,3,4] [1,2,3,4]] Is there any fast way to convert this array to [[1,1,1,1], [2,2,2,2] [3,3,3,3] [4,4,4,4]] In general I would need to retrieve every nth element of the interior arrays in to single arrays. I know I can

Re: 4D arrays

2015-12-02 Thread Manolo Martínez
On 12/01/15 at 06:47pm, Peter Otten wrote: > Extract 2D arrays: > > >>> a[:,2,3] > array([[ 55, 56, 57, 58, 59], >[115, 116, 117, 118, 119]]) > >>> a[1,:,2] > array([[ 70, 71, 72, 73, 74], >[ 90, 91, 92, 93, 94], >

Re: 4D arrays

2015-12-01 Thread Peter Otten
[ 95, 96, 97, 98, 99]], [[100, 101, 102, 103, 104], [105, 106, 107, 108, 109], [110, 111, 112, 113, 114], [115, 116, 117, 118, 119) Extract 2D arrays: >>> a[:,2,3] array([[ 55, 56, 57, 58, 59], [115, 116, 117, 118, 119]]) >>&g

4D arrays

2015-12-01 Thread jorge . conrado
Hi, I use the IDL but now I'm change to PYTHON. I have a 4D array (time, level,lon,lat). I would like to get a 2D array for a specific time (time1) and level (level1). In IDL I use: 2Darray = 4Darray(time1,level1,*,*). How can I get the 2D array in Python Conrado -- https://mail.python.or

Re: Collaps arrays/ list of intergers

2014-08-19 Thread Denis McMahon
On Tue, 19 Aug 2014 05:54:24 -0700, Jurgens de Bruin wrote: > I do hope somebody can help me with the following: > I have the followings lists which represent the upper and lower value of > a range/array. > > a = [1,50] > b = [75,150] > c = [25,42] > d = [120,149] > e = [35,55] I think you're st

Re: Collaps arrays/ list of intergers

2014-08-19 Thread Rock Neurotiko
Hi, I made a fast implementation (I'm sure that can be done better) but it works (for what I understood). Is tested in Python3.4, if you will execute in Python 2.x, or don't have mypy or don't like it, you always can remove the function annotations :) http://gist.github.com/rockneurotiko/017044d

Re: Collaps arrays/ list of intergers

2014-08-19 Thread Peter Otten
Jurgens de Bruin wrote: > Hi All, > > I do hope somebody can help me with the following: > I have the followings lists which represent the upper and lower value of a > range/array. > > a = [1,50] > b = [75,150] > c = [25,42] > d = [120,149] > e = [35,55] > > What I would like to happen is that

Re: Collaps arrays/ list of intergers

2014-08-19 Thread Peter Pearson
On Tue, 19 Aug 2014 05:54:24 -0700 (PDT), Jurgens de Bruin wrote: > > I do hope somebody can help me with the following: > I have the followings lists which represent the upper and lower value > of a range/array. > > a = [1,50] > b = [75,150] > c = [25,42] > d = [120,149] > e = [35,55] > > What I w

Collaps arrays/ list of intergers

2014-08-19 Thread Jurgens de Bruin
Hi All, I do hope somebody can help me with the following: I have the followings lists which represent the upper and lower value of a range/array. a = [1,50] b = [75,150] c = [25,42] d = [120,149] e = [35,55] What I would like to happen is that overlapping range will "collapse" to a single ran

Re: lists vs. NumPy arrays for sets of dates and strings

2014-06-10 Thread Peter Otten
; convenient to work with than lists of lists. What are the advantages and > disadvantages of storing the symbols [A,B] and dates > [2014-01-01,2014-01-02] as lists vs. NumPy arrays? If you don't mind the numpy dependency I can't see any disadvantages. You might also have a look at

Re: lists vs. NumPy arrays for sets of dates and strings

2014-06-09 Thread Denis McMahon
nvenient to work with than lists of lists. What are the advantages and > disadvantages of storing the symbols [A,B] and dates > [2014-01-01,2014-01-02] as lists vs. NumPy arrays? You could also use a dictionary of either lists or tuples or even NumPy arrays keyed on the date. $ python Python

lists vs. NumPy arrays for sets of dates and strings

2014-06-09 Thread beliavsky
storing the symbols [A,B] and dates [2014-01-01,2014-01-02] as lists vs. NumPy arrays? -- https://mail.python.org/mailman/listinfo/python-list

Re: TypeError: only length-1 arrays can be converted to Python

2013-09-21 Thread Oscar Benjamin
,D,x,tinicial)) > File "D:\Yan\Documents\Aptana Studio 3 Workspace\DIF1DMEDYER\SOLUCION NUMERICA PARA LA ECUACION DE LA DIFUSION EN 1D DYER", line 32, in Cdifuana > Cdifuana = (M/temp)*math.exp(-x**2 /(4*D*t)) > TypeError: only length-1 arrays can be converted to Python > The

TypeError: only length-1 arrays can be converted to Python

2013-09-20 Thread D.YAN ESCOLAR RAMBAL
na Cdifuana = (M/temp)*math.exp(-x**2 /(4*D*t)) TypeError: only length-1 arrays can be converted to Python -- *Gracias, cordialmente, * * * * * *ING. YANETH ESCOLAR RAMBAL* *HAFI Engineering & Consulting GmbH* *CEL: + 57 3166257245* *TEL: + 57 (1) 6508308* *TEL: ++43 5522 77924 0

Re: Sum operation in numpy arrays

2013-05-02 Thread Steven D'Aprano
On Thu, 02 May 2013 02:10:11 -0700, Ana Dionísio wrote: > Hello! I have several numpy arrays in my script and i want to add them. > For example: > > a=[1,2,3,4,5] > b=[1,1,1,1,1] > c=[1,0,1,0,1] These are not numpy arrays, they are lists of ints. Based on the error

Re: Sum operation in numpy arrays

2013-05-02 Thread Jens Thoms Toerring
Ana Dionísio wrote: > Hello! I have several numpy arrays in my script and i want to add them. For > example: > a=[1,2,3,4,5] > b=[1,1,1,1,1] > c=[1,0,1,0,1] > for i in range(5): > d[i]=a[i]+b[i]+c[i] > print d > [3,3,5,5,7] > I did it like that

Sum operation in numpy arrays

2013-05-02 Thread Ana Dionísio
Hello! I have several numpy arrays in my script and i want to add them. For example: a=[1,2,3,4,5] b=[1,1,1,1,1] c=[1,0,1,0,1] for i in range(5): d[i]=a[i]+b[i]+c[i] print d [3,3,5,5,7] I did it like that but I get an error: "TypeError: unsupported operand type(s) for +: '

Re: Lists and arrays

2013-04-23 Thread Denis McMahon
On Mon, 22 Apr 2013 11:13:38 -0700, Ana Dionísio wrote: > I have an array and I need pick some data from that array and put it in > a list, for example: > > array= [a,b,c,1,2,3] > > list=array[0]+ array[3]+ array[4] > > list: [a,1,2] > > When I do it like this: list=array[0]+ array[3]+ array[4

Re: Lists and arrays

2013-04-23 Thread 88888 Dihedral
Ana Dionísio於 2013年4月23日星期二UTC+8上午2時13分38秒寫道: > Hello! > > > > I need your help! > > > > I have an array and I need pick some data from that array and put it in a > list, for example: > > > > array= [a,b,c,1,2,3] > > > > list=array[0]+ array[3]+ array[4] > > > > list: [a,1,2] > >

Re: Lists and arrays

2013-04-22 Thread BartC
"Ana Dionísio" wrote in message news:de1cc79e-cbf7-4b0b-ae8e-18841a1ef...@googlegroups.com... Hello! I need your help! I have an array and I need pick some data from that array and put it in a list, for example: array= [a,b,c,1,2,3] list=array[0]+ array[3]+ array[4] list: [a,1,2] When

Re: Lists and arrays

2013-04-22 Thread Dave Angel
On 04/22/2013 02:13 PM, Ana Dionísio wrote: Hello! I need your help! I have an array I think you mean you have a numpy array, which is very different than a python array.array and I need pick some data from that array and put it in a list, for example: array= [a,b,c,1,2,3] That's a li

Lists and arrays

2013-04-22 Thread Ana Dionísio
Hello! I need your help! I have an array and I need pick some data from that array and put it in a list, for example: array= [a,b,c,1,2,3] list=array[0]+ array[3]+ array[4] list: [a,1,2] When I do it like this: list=array[0]+ array[3]+ array[4] I get an error: "TypeError: unsupported operan

Re: Pass numeric arrays from C extensions to Python

2012-09-24 Thread Grant Edwards
On 2012-09-24, JBT wrote: > I am looking for a way to pass numeric arrays, such as *float a[100]; > double b[200];*, from C extension codes to python. The use case of > this problem is that you have data stored in a particular format, > NASA common data format (CDF) in my case, and

Re: Pass numeric arrays from C extensions to Python

2012-09-23 Thread Terry Reedy
On 9/23/2012 9:39 PM, JBT wrote: Hi, I am looking for a way to pass numeric arrays, such as *float a[100]; double b[200];*, from C extension codes to python. The use case of this problem is that you have data stored in a particular format, NASA common data format (CDF) in my case, and there

Re: Pass numeric arrays from C extensions to Python

2012-09-23 Thread Oscar Benjamin
On 24 September 2012 02:39, JBT wrote: > Hi, > > I am looking for a way to pass numeric arrays, such as *float a[100]; > double b[200];*, from C extension codes to python. The use case of this > problem is that you have data stored in a particular format, NASA common > data

Pass numeric arrays from C extensions to Python

2012-09-23 Thread JBT
Hi, I am looking for a way to pass numeric arrays, such as *float a[100]; double b[200];*, from C extension codes to python. The use case of this problem is that you have data stored in a particular format, NASA common data format (CDF) in my case, and there exists an official C library to

Re: Faster way to map numpy arrays

2012-06-26 Thread Oscar Benjamin
me indices but each time changing the array A then you should try precomputing all the indices as a list of numpy arrays (as shown above). On the other hand, if you're repeating with the same matrix A but different sets of indices, you'll need to think about how you are generating t

Re: Faster way to map numpy arrays

2012-06-25 Thread Saurabh Kabra
y say that) and each element > is > > a list of indices to be summed. Then I parse this list with a nested loop > > and compute each element of array B. > > > > Because of the nested loop and the big arrays the process takes a minute > or > > so. My question is:

Re: Faster way to map numpy arrays

2012-06-25 Thread Oscar Benjamin
ted loop > > and compute each element of array B. > > > > Because of the nested loop and the big arrays the process takes a minute > or > > so. My question is: is there a more elegant and significantly faster way > of > > doing this in python? > > I'm sure the

Re: Faster way to map numpy arrays

2012-06-25 Thread Stefan Behnel
rray A to be mapped to array B. The list is the > dimension of array B (if one can technically say that) and each element is > a list of indices to be summed. Then I parse this list with a nested loop > and compute each element of array B. > > Because of the nested loop and the big

Faster way to map numpy arrays

2012-06-24 Thread Saurabh Kabra
dimension of array B (if one can technically say that) and each element is a list of indices to be summed. Then I parse this list with a nested loop and compute each element of array B. Because of the nested loop and the big arrays the process takes a minute or so. My question is: is there a more elegant

loop through arrays and find maximum

2011-12-05 Thread questions anon
I would like to calculate the max and min across many netcdf files. I know how to create one big array and then concatenate and find the numpy.max but when I run this on 1000's of arrays I have a memory error. What I would prefer is to loop through the arrays and produce the maximum without h

Re: Multilevel dicts/arrays v. tuples as keys?

2011-11-14 Thread alex23
Peter Otten <__pete...@web.de> wrote: > If you need lookup only I'd prefer tuples, but sometimes you may want to > retrieve all values with a certain k1 and > > d[k1] > > is certainly more efficient than > > [(k2, v) for (k1, k2), v in d.items() if k1 == wanted] This was the hidden cost of the tup

Re: Multilevel dicts/arrays v. tuples as keys?

2011-11-14 Thread Peter Otten
Matej Cepl wrote: > Dne 11.11.2011 14:31, macm napsal(a): >> def Dicty( dict[k1][k2] ): > > When looking at this I returned to the question which currently rolls in > my mind: > > What's difference/advantage-disadvantage betweeng doing multi-level > dicts/array

Re: Multilevel dicts/arrays v. tuples as keys? [Was: Re: Get keys from a dicionary]

2011-11-14 Thread Tim Golden
On 14/11/2011 10:05, Matej Cepl wrote: Dne 11.11.2011 14:31, macm napsal(a): def Dicty( dict[k1][k2] ): When looking at this I returned to the question which currently rolls in my mind: What's difference/advantage-disadvantage betweeng doing multi-level dicts/arrays like this and using

Multilevel dicts/arrays v. tuples as keys? [Was: Re: Get keys from a dicionary]

2011-11-14 Thread Matej Cepl
Dne 11.11.2011 14:31, macm napsal(a): def Dicty( dict[k1][k2] ): When looking at this I returned to the question which currently rolls in my mind: What's difference/advantage-disadvantage betweeng doing multi-level dicts/arrays like this and using tuple as a key? I.e., is it more Pyt

Re: Assigning generator expressions to ctype arrays

2011-10-29 Thread Patrick Maupin
th > iterators, that would, in my opinion (and see below), That's better for not being absolute. Thank you for admitting other possibilities. > require use of > temporary arrays. Since slice assignment does not use temporary arrays > now (see below), that augmentation should be co

Re: Assigning generator expressions to ctype arrays

2011-10-28 Thread Patrick Maupin
can't believe that. But one of the purposes of the iterator protocol is to reduce the number of cases where you have to create huge lists. > Assignment remains atomic, and the generator will be unpacked into a > temporary list at full C speed. Which can be very slow if your list has s

Re: Assigning generator expressions to ctype arrays

2011-10-28 Thread Steven D'Aprano
On Fri, 28 Oct 2011 16:27:37 -0700, Patrick Maupin wrote: > And, BTW, the example you give of, e.g. > > a,b,c = (some generator expression) > > ALREADY LOSES DATA if the iterator isn't the right size and it raises an > exception. Yes. What's your point? This fact doesn't support your proposal i

Re: Assigning generator expressions to ctype arrays

2011-10-28 Thread Patrick Maupin
On Oct 28, 4:51 pm, Patrick Maupin wrote: > On Oct 28, 3:19 am, Terry Reedy wrote: > > > On 10/28/2011 3:21 AM, Steven D'Aprano wrote: > > > > If the slice has too few elements, you've just blown away the entire > > > iterator for no good reason. > > > If the slice is the right length, but the it

Re: Assigning generator expressions to ctype arrays

2011-10-28 Thread Patrick Maupin
On Oct 28, 3:19 am, Terry Reedy wrote: > On 10/28/2011 3:21 AM, Steven D'Aprano wrote: > > > If the slice has too few elements, you've just blown away the entire > > iterator for no good reason. > > If the slice is the right length, but the iterator doesn't next raise > > StopIteration, you've jus

Re: Assigning generator expressions to ctype arrays

2011-10-28 Thread Terry Reedy
ors, that would, in my opinion (and see below), require use of temporary arrays. Since slice assignment does not use temporary arrays now (see below), that augmentation should be conditional on the source type being a non-sequence iterator. Why would it be a problem to change this? CPytho

Re: Assigning generator expressions to ctype arrays

2011-10-28 Thread Patrick Maupin
On Oct 27, 10:23 pm, Terry Reedy wrote: > I do not think everyone else should suffer substantial increase in space > and run time to avoid surprising you. What substantial increase? There's already a check that winds up raising an exception. Just make it empty an iterator instead. > > It vio

Re: Assigning generator expressions to ctype arrays

2011-10-28 Thread Terry Reedy
On 10/28/2011 3:21 AM, Steven D'Aprano wrote: If the slice has too few elements, you've just blown away the entire iterator for no good reason. If the slice is the right length, but the iterator doesn't next raise StopIteration, you've just thrown away one perfectly good value. Hope it wasn't

Re: Assigning generator expressions to ctype arrays

2011-10-28 Thread Steven D'Aprano
On Thu, 27 Oct 2011 17:09:34 -0700, Patrick Maupin wrote: > On Oct 27, 5:31 pm, Steven D'Aprano +comp.lang.pyt...@pearwood.info> wrote: >> From the outside, you can't tell how big a generator expression is. It >> has no length: > > I understand that. > >> Since the array object has no way of te

Re: Assigning generator expressions to ctype arrays

2011-10-27 Thread Terry Reedy
StopIteration. Given that a cytpe_array is a *fixed-length* array, *unlike* Python's extensible lists and arrays, failure is a possibility due to mis-matched lengths. So ctype_array can either look first, as it does, by calling len(value_object), or leap first and create a temporary array

Re: Assigning generator expressions to ctype arrays

2011-10-27 Thread Patrick Maupin
On Oct 27, 5:31 pm, Steven D'Aprano wrote: > From the outside, you can't tell how big a generator expression is. It has no > length: I understand that. > Since the array object has no way of telling whether the generator will have > the correct size, it refuses to guess. It doesn't have to gu

Re: Assigning generator expressions to ctype arrays

2011-10-27 Thread Steven D'Aprano
On Thu, 27 Oct 2011 13:34:28 -0700, Patrick Maupin wrote: > Bug or misunderstanding? > > Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) [GCC 4.5.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. x = 32 * [0] x[:] = (x for x in xrange(32)) from

Assigning generator expressions to ctype arrays

2011-10-27 Thread Patrick Maupin
Bug or misunderstanding? Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) [GCC 4.5.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> x = 32 * [0] >>> x[:] = (x for x in xrange(32)) >>> from ctypes import c_uint >>> x = (32 * c_uint)() >>> x[:] = xrange(32) >>

Re: Convolution of different sized arrays

2011-07-26 Thread Billy Mays
On 07/26/2011 08:10 AM, Olenka Subota wrote: If anyone of you can help, please do it.. Thanks! You would probably get a better answer asking on one of the mailing lists here: http://new.scipy.org/mailing-lists.html -- http://mail.python.org/mailman/listinfo/python-list

Convolution of different sized arrays

2011-07-26 Thread Olenka Subota
Hello all, I need your help. I have to simulate a filter whose transfer function is a step fct, and I wrote it as a column-vector of Ns elements : >>> h=ones(3,dtype=float) >>> print h [ 1. 1. 1.] >>> h=reshape(h,(3,1)) >>> h array([[ 1.], [ 1.], [ 1.]]) In this case Ns=3 for simp

Re: using masks and numpy record arrays

2011-05-25 Thread Robert Kern
On 5/25/11 3:27 PM, Catherine Moroney wrote: Hello, I am trying to work with a structured array and a mask, and am encountering some problems. You will want to ask numpy questions on the numpy mailing list: http://www.scipy.org/Mailing_Lists For example: >>> xtype = numpy.dtype([("n", n

using masks and numpy record arrays

2011-05-25 Thread Catherine Moroney
Hello, I am trying to work with a structured array and a mask, and am encountering some problems. For example: >>> xtype = numpy.dtype([("n", numpy.int32), ("x", numpy.float32)]) >>> a = numpy.zeros((4), dtype=xtype) >>> b = numpy.arange(0,4) >>> a2 = numpy.zeros((4), dtype=xtype) >>> mask =

Re: Arrays/List, filters, Pytho, Ruby

2011-02-14 Thread LL.Snark
On 12/02/2011 04:49, Terry Reedy wrote: On 2/11/2011 4:24 PM, LL.Snark wrote: Hi, I'm looking for a pythonic way to translate this short Ruby code : t=[6,7,8,6,7,9,8,4,3,6,7] i=t.index {|x| x What does Ruby do if there is no such element? For Python, the answer should be either None or Value

Re: Arrays/List, filters, Pytho, Ruby

2011-02-12 Thread Arnaud Delobelle
Arnaud Delobelle writes: > "LL.Snark" writes: > >> Hi, >> >> I'm looking for a pythonic way to translate this short Ruby code : >> t=[6,7,8,6,7,9,8,4,3,6,7] >> i=t.index {|x| x> > > In Python3: > t = [6,7,8,6,7,9,8,4,3,6,7] next(filter(t[0].__gt__, t)) > 4 Oops! I realised my mistake

Re: Arrays/List, filters, Pytho, Ruby

2011-02-12 Thread Arnaud Delobelle
"LL.Snark" writes: > Hi, > > I'm looking for a pythonic way to translate this short Ruby code : > t=[6,7,8,6,7,9,8,4,3,6,7] > i=t.index {|x| x In Python3: >>> t = [6,7,8,6,7,9,8,4,3,6,7] >>> next(filter(t[0].__gt__, t)) 4 -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Arrays/List, filters, Pytho, Ruby

2011-02-12 Thread DouhetSukd
On Feb 11, 1:24 pm, "LL.Snark" wrote: > Hi, > > I'm looking for a pythonic way to translate this short Ruby code : > t=[6,7,8,6,7,9,8,4,3,6,7] > i=t.index {|x| x > If you don't know Ruby, the second line means : > What is the index, in array t, of the first element x such that x > If can write it

Re: Arrays/List, filters, Pytho, Ruby

2011-02-11 Thread Bruno Piguet
On 11 fév, 22:24, "LL.Snark" wrote: > Hi, > > I'm looking for a pythonic way to translate this short Ruby code : > t=[6,7,8,6,7,9,8,4,3,6,7] > i=t.index {|x| x1000), "not found") or next((i for i, x in enumerate(t) if x>1000), None) or whatever matches your needs. Note that if you use the second o

Re: Arrays/List, filters, Pytho, Ruby

2011-02-11 Thread Terry Reedy
On 2/11/2011 4:24 PM, LL.Snark wrote: Hi, I'm looking for a pythonic way to translate this short Ruby code : t=[6,7,8,6,7,9,8,4,3,6,7] i=t.index {|x| x What does Ruby do if there is no such element? For Python, the answer should be either None or ValueError. If can write it in python several

Re: Arrays/List, filters, Pytho, Ruby

2011-02-11 Thread LL.Snark
On 11/02/2011 22:24, LL.Snark wrote: Hi, I'm looking for a pythonic way to translate this short Ruby code : t=[6,7,8,6,7,9,8,4,3,6,7] i=t.index {|x| x=t[0] : i+=1 ... not pythonic I think... Or : t=[6,7,8,6,7,9,8,4,3,6,7] i=[j for j in range(len(t)) if t[j] Thx for your answers. May I add s

Re: Arrays/List, filters, Pytho, Ruby

2011-02-11 Thread Jon Clements
On Feb 11, 9:24 pm, "LL.Snark" wrote: > Hi, > > I'm looking for a pythonic way to translate this short Ruby code : > t=[6,7,8,6,7,9,8,4,3,6,7] > i=t.index {|x| x > If you don't know Ruby, the second line means : > What is the index, in array t, of the first element x such that x > If can write it

  1   2   3   4   5   6   7   >