recarray

Adding a field to a structured numpy array (2)

走远了吗. 提交于 2019-11-27 15:30:17
I know there was already a question about this topic (cleanest way to add a field to a structured numpy array), see Adding a field to a structured numpy array but I have a question about the answer given there ... If you're using numpy 1.3, there's also numpy.lib.recfunctions.append_fields() I still have numpy 1.3, but it doesn't recognise this function, and I also didn't find anything about it in the documentation of numpy. What happened with the function? Is there another function that can do the same? As far as documentation for the recfunctions, here it is: http://pyopengl.sourceforge.net

numpy recarray strings of variable length

我们两清 提交于 2019-11-27 14:40:26
问题 Is it possible to initialise a numpy recarray that will hold strings, without knowing the length of the strings beforehand? As a (contrived) example: mydf = np.empty( (numrows,), dtype=[ ('file_name','STRING'), ('file_size_MB',float) ] ) The problem is that I'm constructing my recarray in advance of populating it with information, and I don't necessarily know the maximum length of file_name in advance. All my attempts result in the string field being truncated: >>> mydf = np.empty( (2,),

Sorting a python array/recarray by column

只愿长相守 提交于 2019-11-27 11:14:38
I have a fairly simple question about how to sort an entire array/recarray by a given column. For example, given the array: import numpy as np data = np.array([[5,2], [4,1], [3,6]]) I would like to sort data by the first column to return: array([[3,6], [4,1], [5,2]]) NPE Use data[np.argsort(data[:, 0])] where the 0 is the column index on which to sort: In [27]: import numpy as np In [28]: data = np.array([[5,2], [4,1], [3,6]]) In [29]: col = 0 In [30]: data=data[np.argsort(data[:,col])] Out[30]: array([[3, 6], [4, 1], [5, 2]]) you are looking for operator.itemgetter >>> from operator import

Adding a field to a structured numpy array (2)

随声附和 提交于 2019-11-26 17:11:39
问题 I know there was already a question about this topic (cleanest way to add a field to a structured numpy array), see Adding a field to a structured numpy array but I have a question about the answer given there ... If you're using numpy 1.3, there's also numpy.lib.recfunctions.append_fields() I still have numpy 1.3, but it doesn't recognise this function, and I also didn't find anything about it in the documentation of numpy. What happened with the function? Is there another function that can

Sorting a python array/recarray by column

做~自己de王妃 提交于 2019-11-26 15:28:03
问题 I have a fairly simple question about how to sort an entire array/recarray by a given column. For example, given the array: import numpy as np data = np.array([[5,2], [4,1], [3,6]]) I would like to sort data by the first column to return: array([[3,6], [4,1], [5,2]]) 回答1: Use data[np.argsort(data[:, 0])] where the 0 is the column index on which to sort: In [27]: import numpy as np In [28]: data = np.array([[5,2], [4,1], [3,6]]) In [29]: col = 0 In [30]: data=data[np.argsort(data[:,col])] Out