首页
\
问答
\
angular 5在POST请求中获取错误。(angular 5 Getting an error on POST request. Sending header param not works)
angular 5在POST请求中获取错误。(angular 5 Getting an error on POST request. Sending header param not works)
我正在尝试发送POST请求,如:
public getAppData(countryPath) : Observable<any> { const headers = new Headers(); headers.append('Content-Type', 'application/json'); let options = new RequestOptions({ headers: headers }); return this.http.post(this.retailApi, JSON.stringify(this.postParam), {headers: options } ); }
但是我得到一个错误:
这里有什么问题? 任何人都可以帮我弄明白吗?
在我尝试使用另一个选项后,出现此错误:
I am trying to send a POST request like :
public getAppData(countryPath) : Observable<any> { const headers = new Headers(); headers.append('Content-Type', 'application/json'); let options = new RequestOptions({ headers: headers }); return this.http.post(this.retailApi, JSON.stringify(this.postParam), {headers: options } ); }
But I am getting an error as:
What is wrong here? Can anyone help me to figure it out?
after I tried with another option, I got this error:
原文:https://stackoverflow.com/questions/50246233
更新时间:2022-10-10 08:10
最满意答案
我不确定是否存在您想要的软件包,但是此代码计算速度会更快。
>>> arrtrans2 = arr[::2, ::2] + arr[::2, 1::2] + arr[1::2, ::2] + arr[1::2, 1::2] >>> numpy.allclose(arrtrans, arrtrans2) True
其中
::2
和1::2
分别被0, 2, 4, ...
和1, 3, 5, ...
。I'm not sure there exists the package you want, but this code will compute much faster.
>>> arrtrans2 = arr[::2, ::2] + arr[::2, 1::2] + arr[1::2, ::2] + arr[1::2, 1::2] >>> numpy.allclose(arrtrans, arrtrans2) True
Where
::2
and1::2
are translated by0, 2, 4, ...
and1, 3, 5, ...
respectively.
相关问答
更多-
这是一种矢量化方法,通过组合np.unique和np.bincount来获取ID和ID-based求和值的np.bincount - unqID,idx,IDsums = np.unique(ID,return_counts=True,return_inverse=True) value_sums = np.bincount(idx,value.ravel()) 为了将最终输出作为字典获得,可以使用循环理解来收集总和值, {i:(IDsums[itr],value_sums[itr]) for itr, ...
-
聚合numpy功能(Aggregate numpy functions)[2022-08-22]
当使用浮点数组时,可以使用np.einsum - np.sqrt(np.einsum('ij,ij->i',a,a)) 运行时测试 - In [34]: a = np.random.rand(1000,1000) In [35]: np.allclose(np.sum(a**2, axis=1)**.5,np.sqrt(np.einsum('ij,ij->i',a,a))) Out[35]: True In [36]: %timeit np.sum(a**2, axis=1)**.5 100 loop ... -
总结Numpy布尔指数(Summing Numpy Boolean Indices)[2023-07-16]
似乎你需要np.add.reduceat : np.add.reduceat(vals, np.flatnonzero((months - 1) % 12 == 0)) # array([ 12., 24., 36.]) 解释 : months # array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, # 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, ... -
聚合Numpy数组通过求和(Aggregate Numpy Array By Summing)[2022-03-05]
我不确定是否存在您想要的软件包,但是此代码计算速度会更快。 >>> arrtrans2 = arr[::2, ::2] + arr[::2, 1::2] + arr[1::2, ::2] + arr[1::2, 1::2] >>> numpy.allclose(arrtrans, arrtrans2) True 其中::2和1::2分别被0, 2, 4, ...和1, 3, 5, ... 。 I'm not sure there exists the package you want, but this ... -
我很确定由于numpy数组在内部表示的方式而无法避免副本。 数组由连续的内存地址块和一些元数据组成,这些元数据包括数组维度,项目大小以及每个维度的元素之间的分隔(“步幅”)。 向前或向后“滚动”每个元件将需要沿相同尺寸具有不同的长度步幅,这是不可能的。 也就是说,您可以使用切片索引来避免在baseArray复制除一个元素baseArray所有元素: import numpy as np def profile1(seed=0): gen = np.random.RandomState(seed) ...
-
首先,我们可以将ID向量堆叠到一个矩阵中,这样每个ID都是一行三个值: XYZ = np.vstack((x,y,z)).T 现在,我们只需要找到重复行的索引。 不幸的是, np.unique不对行进行操作,所以我们需要做一些技巧 : order = np.lexsort(XYZ.T) diff = np.diff(XYZ[order], axis=0) uniq_mask = np.append(True, (diff != 0).any(axis=1)) 这部分借用了np.unique源代码 ,找到 ...
-
我们可以使用匹配的mask进行boolean-indexing选择那些元素,然后简单地对它们求和,就像这样 - test[test%5==0].sum() 示例一步一步运行 - # Input array In [48]: test Out[48]: array([ 1, 5, 12, 15, 20, 22]) # Mask of matches In [49]: test%5==0 Out[49]: array([False, True, False, True, True, False], ...
-
您可以在使用索引编制索引后直接使用sum : a = np.array([1,2,3,4]) indices = [0, 2] a[indices].sum() You can use sum directly after indexing with indices: a = np.array([1,2,3,4]) indices = [0, 2] a[indices].sum()
-
您可以使用np.bincount和weights参数获得总和。 如果我没有弄错np.bincount是O(n),那么下面的其他代码也是如此: # get the sums cnts = np.bincount(label.ravel(), a.ravel()) # next two lines get indices of the last occurrence of each label psns = np.full(cnts.shape, -1, dtype=int) psns[label.ravel( ...
-
你可以使用np.einsum - y = a*b - np.einsum('i,i,j->j',a,b,b) 我们也可以执行a*b和饲料到einsum - y = a*b - np.einsum('i,j->j',a*b,b) 在第二种方法中,我们可以通过存储a*b并重a*b节省一些运行时间。 运行时测试 - In [253]: a = np.random.rand(4000) In [254]: b = np.random.rand(4000) In [255]: %timeit np.sum(n ...