页: 1 我将阵列变成了一批愤怒。 我应如何这样做?
<>代码>int(> 赢得了t work,因为它说,它可以将其转换成体。 改变<条码>d 类型代码>的外地本身显然不做任何工作,因为实际的墨迹已经改变。 在谷歌或文件中,我似乎找不到什么东西——这是怎样做的最好方法?
页: 1 我将阵列变成了一批愤怒。 我应如何这样做?
<>代码>int(> 赢得了t work,因为它说,它可以将其转换成体。 改变<条码>d 类型代码>的外地本身显然不做任何工作,因为实际的墨迹已经改变。 在谷歌或文件中,我似乎找不到什么东西——这是怎样做的最好方法?
使用<代码>。
>>> a = numpy.array([1, 2, 3, 4], dtype=numpy.float64)
>>> a
array([ 1., 2., 3., 4.])
>>> a.astype(numpy.int64)
array([1, 2, 3, 4])
See documentation 。
虽然<条码>作为类型代码>可能是“最佳”选择,但也有几种其他方法将其转换成一个分类阵列。 采用<代码>arr的Im 实例如下:
>>> import numpy as np
>>> arr = np.array([1,2,3,4], dtype=float)
>>> arr
array([ 1., 2., 3., 4.])
int*
functions from NumPy>>> np.int64(arr)
array([1, 2, 3, 4])
>>> np.int_(arr)
array([1, 2, 3, 4])
*array
functions themselves:>>> np.array(arr, dtype=int)
array([1, 2, 3, 4])
>>> np.asarray(arr, dtype=int)
array([1, 2, 3, 4])
>>> np.asanyarray(arr, dtype=int)
array([1, 2, 3, 4])
astype
method (that was already mentioned but for completeness sake):>>> arr.astype(int)
array([1, 2, 3, 4])
请注意,通过<条码>int作为<条码>的模版条码>或<条码>,将出现一种基于你的平台的缺省分类。 例如,在Windows上,它将在64bit int32
上,与64bit Zhu其int<64>/code>。 如果您需要一种具体的分类类型,并想避免平台的“模糊”,那么你应当使用相应的NumPy类型,如
np.int32
或np.int64
。
还进行了真正有益的讨论,将现有的阵列转换成。 单体阵列的内型转换。 如果你对复制贵国的阵列(即<条码>的类型>条码>)表示担心,则肯定会核对这一联系。
所有我都使用过。
numpyfloat = (1.0, 2.0, 4.0)
a = numpy.array(numpyfloat, dtype=numpy.int)
那是
Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...
I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...
Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...
Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...
I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...
Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...
Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...
I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...