Re: [Numpy-discussion] Need **working** code example of 2-D arrays
On Sun, Oct 12, 2008 at 3:39 PM, Linda Seltzer <[EMAIL PROTECTED]> wrote: > These are the import statements I used: > import numpy as npy > from numpy.oldnumeric import * Here is an example that works for any working numpy installation: import numpy as npy npy.zeros((256, 256)). If those are the first two statements at python prompt, and it does not work, your numpy installation is broken. In that case, which platform and how did you install numpy would be useful information to help you better. > Please, no demeaning statements like "you forgot a parenthesis" or "you > were using someone else's code" - just the lines of code for a file that > actually *works.* Those were not demeaning statements, and the line that works was shown to you. I strongly suspect that either you did not give use enough information, or that your numpy installation is broken. cheers, David ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Need **working** code example of 2-D arrays
On Sun, Oct 12, 2008 at 03:11, David Cournapeau <[EMAIL PROTECTED]> wrote: > On Sun, Oct 12, 2008 at 3:39 PM, Linda Seltzer > <[EMAIL PROTECTED]> wrote: > >> These are the import statements I used: >> import numpy as npy >> from numpy.oldnumeric import * > > Here is an example that works for any working numpy installation: > > import numpy as npy > npy.zeros((256, 256)). Well, except for that last period. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Proposal: scipy.spatial
2008/10/9 David Bolme <[EMAIL PROTECTED]>: > I have written up basic nearest neighbor algorithm. It does a brute > force search so it will be slower than kdtrees as the number of points > gets large. It should however work well for high dimensional data. I > have also added the option for user defined distance measures. The > user can set a default "p". "p" has the same functionality if it is a > float. "p" can also be a function that computes a distance matrix or > the measure can be selected using the strings: "Manhattan", > "Euclidean", or "Correlation". > > https://pyvision.svn.sourceforge.net/svnroot/pyvision/trunk/src/pyvision/vector/knn.py This is interesting. I would point out, though, that if you want a Minkowski norm, it may be more efficient (that is, faster) to use the new compiled kd-tree implementation with leafsize set to the size of your data. This is written in compiled code and uses short-circuit distance evaluation, and may be much faster for high-dimensional problems. Given that, this should perhaps go in with other generic metric space code. I have a functional implementation of ball trees (though I don't know how efficient they are), and am looking into implementing cover trees. > The interface is similar to Anne's code and in many cases can be used > as a drop in replacement. I have posted the code to my own project > because I have a short term need and I do not have access to the scipy > repository. Feel free to include the code with scipy under the scipy > license. > > I did find a typo your documentation. > typo "trie -> tree" - ... kd-tree is a binary trie, each of whose ... That's not actually a typo: a trie is a tree in which all the data is stored at leaf nodes. Basic kd-trees use the nodes themselves to define splitting planes; you can actually construct one with no extra storage at all, just by choosing an appropriate order for your array of points. This implementation chooses splitting planes that may not pass through any point, so all the points get stored in leaves. > Also I found the use of k in the documentation some what confusing as > it is the dimensionality of the data points in the kd-tree and the > number of neighbors for k-nearest neighbors. That's a good point. I changed the dimension of the kd-tree to m throughout. Anne ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] Data types in Numerical Python
> Here is an example that works for any working numpy installation: > > import numpy as npy > npy.zeros((256, 256)) This suggestion from David did work so far, and removing the other import line enabled the program to run. However, the data types the program used as defaults for variables has changed, and now I am getting error messages about data types. It seems that some variables are getting a default designation as floats. Before I installed numpy and needed 2-D arrays, the program was working with the default types, and I did not have to specify types. Is there a clear tutorial that describes a means to assign data types for each variable as in C, so that I don't obtain error messages about data types? Because I am simulating code for a DSP processor, the data types I need are unsigned bytes, unsigned 32-bit ints, and signed 32-bit ints. In some cases I can use unsigned and signed 16-bit ints. Also, what data types are valid for use with local operations such as exclusive or? ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Data types in Numerical Python
2008/10/12 Linda Seltzer <[EMAIL PROTECTED]>: >> Here is an example that works for any working numpy installation: >> >> import numpy as npy >> npy.zeros((256, 256)) > This suggestion from David did work so far, and removing the other import > line enabled the program to run. > However, the data types the program used as defaults for variables has > changed, and now I am getting error messages about data types. It seems > that some variables are getting a default designation as floats. Before I > installed numpy and needed 2-D arrays, the program was working with the > default types, and I did not have to specify types. > Is there a clear tutorial that describes a means to assign data types for > each variable as in C, so that I don't obtain error messages about data > types? Python is a dynamically-typed language (unlike C), so variables do not have type. That is, a variable can refer to an object of any type; if you need to know what type of object a variable currently refers to you must inspect the object. You may want to go through one of the brief introduction-to-python tutorials that are on the python website just to get comfortable with the language. (For example, understanding the meaning and syntax of import statements.) When you create a numpy array, you can specify its type. You can also explicitly or implicitly convert the types of numpy arrays. I recommend you select a data type, let's say np.uint32, and make sure various arrays are created containing that type: np.zeros((m,n),dtype=np.uint32) np.arange(10,dtype=np.uint32) x.astype(np.uint32) np.array([1,2,3,4.5], dtype=np.uint32) et cetera. Most operations (addition, multiplication, maximum) will preserve the data type of arrays they are given (but if you supply two different data types numpy will attempt to choose the "larger"). > Because I am simulating code for a DSP processor, the data types I need > are unsigned bytes, unsigned 32-bit ints, and signed 32-bit ints. In some > cases I can use unsigned and signed 16-bit ints. > Also, what data types are valid for use with local operations such as > exclusive or? The numpy data types you want are described by "dtype" objects. These can in principle become quite complicated, but the ones you need are given names already: np.uint8 np.uint32 np.int32 np.uint16 np.int16 You can specify any of these as "dtype=" arguments to the various numpy functions. If you need really rigid typing, python may not be the ideal language for you. Good luck, Anne ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Data types in Numerical Python
Linda Seltzer wrote: Here is an example that works for any working numpy installation: import numpy as npy npy.zeros((256, 256)) This suggestion from David did work so far, and removing the other import line enabled the program to run. However, the data types the program used as defaults for variables has changed, and now I am getting error messages about data types. It seems that some variables are getting a default designation as floats. Before I installed numpy and needed 2-D arrays, the program was working with the default types, and I did not have to specify types. Is there a clear tutorial that describes a means to assign data types for each variable as in C, so that I don't obtain error messages about data types? Because I am simulating code for a DSP processor, the data types I need are unsigned bytes, unsigned 32-bit ints, and signed 32-bit ints. In some cases I can use unsigned and signed 16-bit ints. Also, what data types are valid for use with local operations such as exclusive or? ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion You can specify the type in the zeros command import numpy as npy npy.zeros((256, 256), npy.uint32) or you can convert an array between types at any point using the .astype(npy.uint16) notation like this npy.zeros((256,256)).astype(npy.uint16) I am not sure if there are any tutorials on this, but here are the types you are interested in: npy.uint32 npy.uint16 npy.int32 npy.int16 ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Data types in Numerical Python
On Oct 12, 2008, at 5:26 PM, Anne Archibald wrote: > Python is a dynamically-typed language (unlike C), so variables do not > have type. Another way to think of it for C people is that all variables have the same type, which is "reference to Python object." It's the objects which are typed, and not the variable. Andrew [EMAIL PROTECTED] ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Data types in Numerical Python
On Sun, Oct 12, 2008 at 9:11 AM, Linda Seltzer <[EMAIL PROTECTED]>wrote: > > Here is an example that works for any working numpy installation: > > > > import numpy as npy > > npy.zeros((256, 256)) > This suggestion from David did work so far, and removing the other import > line enabled the program to run. > However, the data types the program used as defaults for variables has > changed, and now I am getting error messages about data types. It seems > that some variables are getting a default designation as floats. Before I > installed numpy and needed 2-D arrays, the program was working with the > default types, and I did not have to specify types. Yes, the default type of the functions zeros and ones have changed from integer to float. If your program is short you could send it as an attachment so we could look at it. Chuck ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Need **working** code example of 2-D arrays
On 10/12/2008 2:39 AM Linda Seltzer apparently wrote: > Please, no demeaning statements like "you forgot > a parenthesis" or "you were using someone else's code" > - just the lines of code for a file that actually *works.* Those statements are not demeaning; lighten up. And the answer was correct. Start up an interpreter prompt. Type these in. What happens? >>> import numpy as np >>> a = np.zeros((256,256)) Cheers, Alan Isaac ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Need **working** code example of 2-D arrays
> > Those statements are not demeaning; lighten up. STOP IT. JUST STOP IT. STOP IT RIGHT NOW. Is there a moderator on the list to put a stop to these kinds of statements? I deserve to be treated with respect. I deserve to have my questions treated with respect. I deserve to receive technical information without personal attacks. ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Need **working** code example of 2-D arrays
Friends, >> Those statements are not demeaning; lighten up. > STOP IT. JUST STOP IT. STOP IT RIGHT NOW. Let us not go to this place, honestly, there is no need. Let's go back to the technical problem again. Linda, did you have time to try Alan's example? Best, Matthew ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Need **working** code example of 2-D arrays
L. Brooks of M.I.T. sent a professional e-mail with a code fragment that has worked. > Friends, > >>> Those statements are not demeaning; lighten up. >> STOP IT. JUST STOP IT. STOP IT RIGHT NOW. > > Let us not go to this place, honestly, there is no need. Let's go > back to the technical problem again. > > Linda, did you have time to try Alan's example? > > Best, > > Matthew > ___ > Numpy-discussion mailing list > Numpy-discussion@scipy.org > http://projects.scipy.org/mailman/listinfo/numpy-discussion > ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Need **working** code example of 2-D arrays
Linda, If you're familiar with Matlab syntax, you may find this link interesting: http://www.scipy.org/NumPy_for_Matlab_Users Here another couple of useful links http://www.scipy.org/Tentative_NumPy_Tutorial http://www.scipy.org/Numpy_Functions_by_Category For your specific example, if you want to create a (256,128) array of unsigned integers: import numpy as np a = np.zeros((256,128), dtype=np.uint32) Note that if you intend to fill the array afterwards with other values, it might be more efficient to create an 'empty' array instead of an array full of zeros: b=np.empty((256,128), dtype=uint32) ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion