Re: [Numpy-discussion] numpy arrays
On Sat, Jun 9, 2012 at 2:12 PM, bob tnur wrote: >> >> how to save multiple files like cm1.txt,cm2.txt,cm3.txt etc and to >> produce their corresponding outputs cm1.out,cm2.out,cm3.out etc. > > or how to modify this: > np.savetxt(fname, (a,b), fmt='%4.8f') > You can save them to separate files with a for loop. for i, arr in enumerate([a, b]): fname = 'cm{}.out'.format(i + 1) np.savetxt(fname, arr, fmt='%4.8f') ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] numpy arrays
How do you want the output files to be formatted? Binary data? Textual representation? This function can do both: http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.tofile.html And numpy supports a variety of methods for outputting to files (and reading data back in): http://docs.scipy.org/doc/numpy/reference/routines.io.html --PLR On Fri, Jun 8, 2012 at 11:04 AM, bob tnur wrote: > Hi every body! > I have a &b numpy arrays > a=np.loadtxt('çm1.txt', dtype=np.float, skiprows=2,usecols=[1]) > b=np.loadtxt('çm1.txt', dtype=('x', np.float64), skiprows=2,usecols=[2]) > > 1. I want to save or write these two arrays and able to see the output as > output file, say cm1.out. what about if I have multiple files like > cm1.txt,cm2.txt,cm3.txt etc and to produce their corresponding outputs > cm1.out,cm2.out,cm3.out etc. > > I appreciate your help > > > ___ > NumPy-Discussion mailing list > NumPy-Discussion@scipy.org > http://mail.scipy.org/mailman/listinfo/numpy-discussion > ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] 1D array sorting ascending and descending by fields
On Mon, Jun 4, 2012 at 6:08 PM, Chris Barker wrote: > could you multiply the numeric field by -1, sort, then put it back > Yeah, that works great for my situation. Thanks Chris! On Mon, Jun 4, 2012 at 8:17 PM, Benjamin Root wrote: > While that may work for this users case, that would not work for all dtypes. > Some, such as timedelta, datetime and strings would not be able to be > multiplied by a number. > This is the reason why I thought there might be such a feature. > Would be an interesting feature to add, but I am not certain if the negative > sign notation would be best. Is it possible for a named field to start with > a negative sign? > I'm not sure about what is allowable in names, but I would be interested in getting involved with the NumPy project by helping to add this feature. I'll check out the contributing doc. ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] 1D array sorting ascending and descending by fields
Here's how I sorted primarily by field 'a' descending and secondarily by field 'b' ascending: (Note that 'a' is the second column, 'b' is the first) >>> data array([('b', 0.03), ('c', 0.03), ('f', 0.03), ('e', 0.01), ('d', 0.04), ('a', 0.04)], dtype=[('b', '|S32'), ('a', '>> data.sort(order='b') # sort by b >>> data = data[::-1] # reverse >>> data[numpy.argsort(data['a'])][::-1] # sort by a and reverse array([('a', 0.04), ('d', 0.04), ('b', 0.03), ('c', 0.03), ('f', 0.03), ('e', 0.01)], dtype=[('b', '|S32'), ('a', '>> data.sort(order=('-a', 'b')) ...indicating that the order of 'a' is descending, but this isn't part of NumPy's sort behavior. Your help is appreciated! Thank you, Patrick ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] 1D array sorting ascending and descending by fields
Hi! I have a one-dimensional ndarray with two fields. I'd like to sort in descending order by field 'a', breaking ties by sorting in ascending order by field 'b'. I've found combinations of sorting and reversing followed by stable sorting that work, but there must be a straightforward way to do it. Your help is appreciated! Thank you, Patrick ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion