在android 2.x上创建Uint8array的替代品(create a substitute of Uint8array on android 2.x)
我正在开发一个关于android的phonegap的应用程序。 我希望该应用程序可以在Android 2.3.3和更多。 我在我的代码上使用Uint8array。 这个工作在android 4但不在android 2.我有这个错误:
找不到变量:Uint8array
我做了一些研究,发现android2上不支持uint8array。 我想知道是否有一个类似的功能或一个可以在android 2上运行的库。
谢谢
I'm developping an application on phonegap for android. I would like that the application can work on android 2.3.3 and more. I use Uint8array on my code. this work on android 4 but not on android 2. I've got this error:
can't find variable: Uint8array
I do some research and found that uint8array is not supported on android2. I would like to know if there is a similiar function or a library that work on android 2.
Thank you
原文:https://stackoverflow.com/questions/16735218
最满意答案
np.savetxt
写入一维数组,每行一个元素。
np.savetxt
写入每行一行的二维数组。这解释了为什么
scipy.savetxt('y.txt', y...)
为您提供了一个长列。 此外,numpy / scipy认为(x, y)
是一维元组,而不是二维数组。 这就是你得到的原因0 1 2 3 4 5 10 11 12 13 14 15
输出。
因此,要获得所需的输出,请传递二维数组。 正如您所指出的,使用
np.column_stack
可能是最简单的方法:import numpy as np np.savetxt(filename, np.column_stack((x,y)), fmt='%g')
要将数据读回
x
和y
变量,请使用unpack=True
参数:x, y = np.genfromtxt(filename, unpack=True)
np.savetxt
writes 1-dimensional arrays with one element per line.
np.savetxt
writes 2-dimensional arrays with one row per line.This explains why
scipy.savetxt('y.txt', y...)
gives you one long column. Also, numpy/scipy considers(x, y)
to be a 1-dimensional tuple, not a 2-dimensional array. This is why you get0 1 2 3 4 5 10 11 12 13 14 15
for output.
So, to get the desired output, pass a 2-dimensional array. Using
np.column_stack
, as you noted, is probably the easiest way:import numpy as np np.savetxt(filename, np.column_stack((x,y)), fmt='%g')
To read the data back into
x
andy
variables, use theunpack=True
parameter:x, y = np.genfromtxt(filename, unpack=True)
相关问答
更多-
查找x和y坐标的numpy数组中最近点的索引(Finding index of nearest point in numpy arrays of x and y coordinates)[2023-03-20]
scipy.spatial也有一个kd树实现: scipy.spatial.KDTree 。 该方法通常首先使用点数据来建立一个kd树。 其计算复杂度在N log N的数量级,其中N是数据点的数量。 然后可以使用日志N复杂度来完成范围查询和最近邻搜索。 这比简单地循环通过所有点(复杂度N)要高得多。 因此,如果您有重复的范围或最近邻居查询,强烈建议使用kd树。 scipy.spatial also has a k-d tree implementation: scipy.spatial.KDTree. Th ... -
加入dplyr时如何指定x和y列的名称?(How to specify names of columns for x and y when joining in dplyr?)[2022-04-07]
此功能已添加到dplyr v0.3中。 您现在可以将命名的字符向量传递给left_join (和其他加入函数)中by参数,以指定在每个数据帧中加入哪些列。 以原始问题给出的例子,代码将是: left_join(test_data, kantrowitz, by = c("first_name" = "name")) This feature has been added in dplyr v0.3. You can now pass a named character vector to the by a ... -
用相应的x(x和y是数组)搜索min(y)(searching for min(y) with the corresponding x (x and y are arrays))[2024-01-04]
在没有测试y是否有min(不知道这是否是没有更多源的应用程序的要求)的情况下,使用np.argmin() : import numpy as np x = np.array([3900.06, 3900.16, 3900.26]) y = np.array([0.311254, 0.588623, 0.724301]) print(x[np.argmin(y)]) Without testing whether or not y has a min (not sure if this is a req ... -
你可以用熊猫来做到这一点,熊猫可以管理缺失的值。 但文件的第一行必须是所有文件中最长的一行 。 Pandas使用标题行确定数据帧的宽度。 举个例子 : 假设x.csv是: 1,2,3,4 1,2,3,4,5 1,2 添加第一列,长或超过最长: a,a,a,a,a,a,a,a,a,a 1,2,3,4 1,2,3,4,5 1,2 然后阅读: x=pd.read_csv('x.csv')和y=pd.read_csv('y.csv') 。 plt.plot(xT,yT)就是你想要的。 You can effec ...
-
你可以试试 Un <- unique(unlist(ds[1:2])) m1 <- matrix(0, length(Un),length(Un), dimnames=list(Un, Un)) m1[as.matrix(ds[1:2])] <- ds[,3] m1 <- m1+t(m1) diag(m1) <- NA identical(m1, mx) #[1] TRUE 更新 基于新数据集,这可能有效 ds1 <- read.csv('lulc.mean21apr2015.csv') library ...
-
所以看着我的猜测,我试过了axis = 1 。 我仔细检查了唯一有意义的其他选项, axis = 0 ,并且它有效。 所以对于下一个有同样问题的假人来说,这就是我想要的: In [14]: interp_data = interpolate.interp1d(data[:,0], data[:,1:], axis=0, kind='cubic') In [15]: data_int = np.zeros((len(new_x),len(data[0]))) In [16]: data_int[:,0] = ...
-
您需要将vstack的输出分配给循环中的data : for i in range(len(activities_and_attractions.index)): data = np.vstack((data, np.array([activities_and_attractions.X[i], activities_and_attractions.Y[i]]))) # assign to data 考虑使用numpy.append执行此任务。 以这种方式发展ndarray效率不高。 出了什么问 ...
-
np.savetxt写入一维数组,每行一个元素。 np.savetxt写入每行一行的二维数组。 这解释了为什么scipy.savetxt('y.txt', y...)为您提供了一个长列。 此外,numpy / scipy认为(x, y)是一维元组,而不是二维数组。 这就是你得到的原因 0 1 2 3 4 5 10 11 12 13 14 15 输出。 因此,要获得所需的输出,请传递二维数组。 正如您所指出的,使用np.column_stack可能是最简单的方法: import numpy as np np ...
-
for y in specdt: # <--- x = Concentration slope, intercept, r_value, p_value, std_err = stats.linregress(x,y) for循环已经给出了行本身的内容。 如果你想要行索引,请使用 for row, y in enumerate(specdt): ... for y in specdt: # <--- x = Concentration slope, i ...
-
两种解决方案 直接计算完整矩阵,并访问第q列,得到A和B [q]之间的值。 d = scipy.spatial.distance.cdist(A,B) for q in range(len(B)): y = d[:,q] print y 如果结果矩阵太大而无法保存在内存中。 你可以做到这一点。 for q in range(len(B)): y = scipy.spatial.distance.cdist(A,[B[q]]) print y Two solutions: ...