map-function

Idris - map function on custom dependent data type fails

放肆的年华 提交于 2019-12-24 01:47:07
问题 I am relatively new to idris and dependent-types and I encountered the following problem - I created a custom data type similar to vectors: infixr 1 ::: data TupleVect : Nat -> Nat -> Type -> Type where Empty : TupleVect Z Z a (:::) : (Vect o a, Vect p a) -> TupleVect n m a -> TupleVect (n+o) (m+p) a exampleTupleVect : TupleVect 5 4 Int exampleTupleVect = ([1,2], [1]) ::: ([3,4],[2,3]) ::: ([5], [4]) ::: Empty It is inductively constructed by adding tuples of vectors and indexed by the sum of

Why is this recursive map function only being applied to the last two elements in the list?

半城伤御伤魂 提交于 2019-12-24 01:18:33
问题 This is the problem given: What are the first 8 elements in the following list? mystery = 0 : 10 : (map(+1)mystery) The answer is [0,10,1,11,2,12,3,13...] But in my opinion the answer should be [0,10,1,11,1,11,2,12] . The following steps show why: 1) We are given ;list [0,10] so after applying the function the first time we have the list [ 0,10,1, 11] 2) Now we have a list [ 0,10,1,11] so after applying the function again the resulting list should be [0,10,1,11,1,11,2,12] Apparently that is

Exclude null values in map function of Python3

蓝咒 提交于 2019-12-23 02:52:33
问题 I am using map to process a list in Python3.6: def calc(num): if num > 5: return None return num * 2 r = map(lambda num: clac(num), range(1, 10)) print(list(r)) # => [2, 4, 6, 8, 10, None, None, None, None] The result I expect is: [2, 4, 6, 8, 10] . Of course, I can use filter to handle map result. But is there a way for map to return directly to the result I want? 回答1: map cannot directly filter out items. It outputs one item for each item of input. You can use a list comphrehension to

Python 3 map dictionary update method to a list of other dictionaries [duplicate]

独自空忆成欢 提交于 2019-12-22 04:12:28
问题 This question already has answers here : Getting a map() to return a list in Python 3.x (8 answers) Closed 4 years ago . In Python 2 I can do the following: >> d = {'a':1} >> extras = [{'b':2}, {'c':4}] >> map(d.update, extras) >> d['c'] >> 4 In Python 3 in get a KeyError : >> d = {'a':1} >> extras = [{'b':2}, {'c':4}] >> map(d.update, extras) >> d['c'] >> KeyError: 'c' I would like to achieve the same behavior in Python 3 as in Python 2. I understand that map in Python 3 will return an

Python 3 map dictionary update method to a list of other dictionaries [duplicate]

旧巷老猫 提交于 2019-12-22 04:12:07
问题 This question already has answers here : Getting a map() to return a list in Python 3.x (8 answers) Closed 4 years ago . In Python 2 I can do the following: >> d = {'a':1} >> extras = [{'b':2}, {'c':4}] >> map(d.update, extras) >> d['c'] >> 4 In Python 3 in get a KeyError : >> d = {'a':1} >> extras = [{'b':2}, {'c':4}] >> map(d.update, extras) >> d['c'] >> KeyError: 'c' I would like to achieve the same behavior in Python 3 as in Python 2. I understand that map in Python 3 will return an

Backpropagating gradients through nested tf.map_fn

好久不见. 提交于 2019-12-21 19:49:22
问题 I would like to map a TensorFlow function on each vector corresponding to the depth channel of every pixel in a matrix with dimension [batch_size, H, W, n_channels] . In other words, for every image of size H x W that I have in the batch: I extract some features maps F_k (whose number is n_channels) with the same size H x W (hence, the features maps all together are a tensor of shape [H, W, n_channels] ; then, I wish to apply a custom function to the vector v_ij that is associated with the i

Mapping Array in Javascript with sequential numbers

限于喜欢 提交于 2019-12-21 02:22:14
问题 The following code: let myArray = Array.apply(null, {length: 10}).map(Number.call, Number); Creates the following Array: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] I just don't understand why. I can't find anything on the internet that explains this behavior. Does anyone know why this works the way it does? Perhaps a link to some documentation? 回答1: Array.apply(null, {length: 10}) creates an array of length 10 with all elements being undefined . .map(Number.call, Number) will invoke Number.call for each

Map, Filter, Foldr in DrRacket/Scheme

狂风中的少年 提交于 2019-12-20 19:38:36
问题 Programming language: Scheme/DrRacket We're currently going over map , filter , and foldr in my comp sci class. I understand that all three can be used to create abstract functions, but I am honestly a little confused about the difference between the three and when I'd use each one. Anyone care to explain what each is used for and how they are different? Unfortunately my book is not very clear. 回答1: The basic idea is that all three are ways of applying some function to all the elements of a

Java - Spark SQL DataFrame map function is not working

こ雲淡風輕ζ 提交于 2019-12-18 13:34:44
问题 In Spark SQL when I tried to use map function on DataFrame then I am getting below error. The method map(Function1, ClassTag) in the type DataFrame is not applicable for the arguments (new Function(){}) I am following spark 1.3 documentation as well. https://spark.apache.org/docs/latest/sql-programming-guide.html#inferring-the-schema-using-reflection Have any one solution? Here is my testing code. // SQL can be run over RDDs that have been registered as tables. DataFrame teenagers =

Using multiple map functions vs. a block statement in a map in a java stream

本秂侑毒 提交于 2019-12-17 16:33:56
问题 Say I have the following code data.stream() .map(x -> { Object a = maybeReturnsNull(x); return a == null ? defaultValue : a; }) I have some function that might be returning null , and I'm applying it to an element of the stream. I then want to make sure that any null results get changed to some default value instead. Is there any significant difference between using two maps as in the following example, as compared to using the previous example that defines a helper variable a and uses a code