array

Filter array in ios checking multiple properties

匿名 (未验证) 提交于 2019-12-03 03:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an array of custom objects. The custom object look like this @interface User : NSObject @property(nonatomic, strong)NSString *user_Id; @property(nonatomic, strong)NSString *user_Name; @property(nonatomic, strong)NSString *user_UserName; @end I have to filter the array checking 2 properties.That is if I search a then it should get list of users filtered from array contains a in user_Name or user_Id .How can i achieve this? For a single property i know[user_Name] NSString *predicateString = @"user_Name MATCHES[c] %@"; NSString

Algorithm to generate RGB graduated colors in PHP

匿名 (未验证) 提交于 2019-12-03 03:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm interesting in algorithms to generate 'n' graduated colors between two given colors, that generate smooth transitions between each of them. I tried letting static two channels, for example R and G, and incremental change B, but sometimes the difference between two colors are harder than the neighbors have. I want to check different algorithms and analyze their weakness and strenghts. I wrote this code and it seems logic, but the transitions between some colors are harder than between other (e.g.between 0 and 1 is harder than

C++ Array Subscript Operator Template

匿名 (未验证) 提交于 2019-12-03 03:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: After trying to make access to a storage class a little easier, I ended up in a situation that I don't have a lot of knowledge on. And, finding people that are trying to do the same thing as me isn't easy. What I'm trying to do, is have a class that stores an array of values as strings internally, but allows simple type casting from the user's end. What I had planned on doing is use the array subscript operator to return whichever type they specify through a template. Although, it sounds a lot better than it works in practice. Here's a

Longest convex subsequence in an array

匿名 (未验证) 提交于 2019-12-03 03:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Suppose we are given an input array of integers, how to find the longest convex subsequence that satisfies the following condition: c[i] < (c[i-1] + c[i+1]) / 2 c[i-1] , c[i] and c[i+1] are three consecutive elements in the subsequence. For example, if input array is { 1, 2, -1, 0, 3, 8, 5 } , the longest convex subsequence should be: { 1, -1, 0, 3, 8 } or { 2, -1, 0, 3, 8 } . I tried to solve this problem using the same dynamic programming idea in "Longest Increasing Subsequence" (LIS) problem. But because each element in the subsequence

Swig, returning an array of doubles

匿名 (未验证) 提交于 2019-12-03 03:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I know, there are often many ways to solve certain problems. But here I know which way I want to have it, but I am unable to make it work with Python and SWIG... I have a C-function, which returns me an array of double values: double *my(int x) { double a,b,*buf; buf = malloc (x * sizeof(double)); a=3.14; b=2.7; buf[0]=a; buf[1]=b; return buf; } Here, I definitively want to have the array as a return value. Not, as in many examples a 'void' function, which writes into an input array. Now, I would like to get a SWIG-python wrapper, which

How to efficiently store and update binary data in Mongodb?

匿名 (未验证) 提交于 2019-12-03 03:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am storing a large binary array within a document. I wish to continually add bytes to this array and sometimes change the value of existing bytes. I was looking for some $append_bytes and $replace_bytes type of modifiers but it appears that the best I can do is $push for arrays. It seems like this would be doable by performing seek-write type operations if I had access somehow to the underlying bson on disk, but it does not appear to me that there is anyway to do this in mongodb (and probably for good reason). If I were instead to just

Using Numpy Vectorize on Functions that Return Vectors

匿名 (未验证) 提交于 2019-12-03 03:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: numpy.vectorize takes a function f:a->b and turns it into g:a[]->b[]. This works fine when a and b are scalars, but I can't think of a reason why it wouldn't work with b as an ndarray or list, i.e. f:a->b[] and g:a[]->b[][] For example: import numpy as np def f ( x ): return x * np . array ([ 1 , 1 , 1 , 1 , 1 ], dtype = np . float32 ) g = np . vectorize ( f , otypes =[ np . ndarray ]) a = np . arange ( 4 ) print ( g ( a )) This yields: array ([[ 0. 0. 0. 0. 0. ], [ 1. 1. 1. 1. 1. ], [ 2. 2. 2. 2. 2. ], [ 3. 3. 3. 3. 3. ]], dtype =

Transfer ownership of numpy data

匿名 (未验证) 提交于 2019-12-03 03:05:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In my previous question , I learned to resize a subclassed ndarray in place. Neat. Unfortunately, that no longer works when the array that I am trying to resize is the result of a computation: import numpy as np class Foo(np.ndarray): def __new__(cls,shape,dtype=np.float32,buffer=None,offset=0, strides=None,order=None): return np.ndarray.__new__(cls,shape,dtype,buffer,offset,strides,order) def __array_prepare__(self,output,context): print output.flags['OWNDATA'],"PREPARE",type(output) return np.ndarray.__array_prepare__(self,output,context)

Why is ES6 “yield” a reserved word when called in this context?

匿名 (未验证) 提交于 2019-12-03 03:05:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am using node 4.1.1. When I run this code "use strict"; function *generator() { let numbers = [1,2,3,4,5]; numbers.map(n => yield (n + 1)); } for (var n of generator()) { console.log(n); } I get this error numbers.map(n => yield (n + 1)); ^^^^^ SyntaxError: Unexpected strict mode reserved word If I rearrange the code to be this "use strict"; function *generator() { let numbers = [1,2,3,4,5]; let higherNumbers = numbers.map(n => n + 1); for(let i=0;i<higherNumbers.length;i++) { yield higherNumbers[i]; } } for (var n of generator()) {

Convert map object to numpy array in python 3

匿名 (未验证) 提交于 2019-12-03 03:05:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In Python 2 I could do the following: import numpy as np f = lambda x: x**2 seq = map(f, xrange(5)) seq = np.array(seq) print seq # prints: [ 0 1 4 9 16] In Python 3 it does not work anymore: import numpy as np f = lambda x: x**2 seq = map(f, range(5)) seq = np.array(seq) print(seq) # prints: <map object at 0x10341e310> How do I get the old behaviour (converting the map results to numpy array)? Edit : As @jonrsharpe pointed out in his answer this could be fixed if I converted seq to a list first: seq = np.array(list(seq)) but I would prefer