range

Why does map return an additional element when using ranges in Haskell?

别等时光非礼了梦想. 提交于 2019-12-01 17:09:54
I've just started learning Haskell and found a strange thing. Let we have a list: ghci> [0,2..5] [0,2,4] It has 3 elements. When I use map with this list I get 3 element as output, for example: ghci> map (+ 1) [0,2..5] [1,3,5] ghci> map (* 2) [0,2..5] [0,4,8] ghci> map (`div` 2) [0,2..5] [0,1,2] But when I use fractional division I get 4 elements in output list: ghci> map (/ 2) [0,2..5] [0.0,1.0,2.0,3.0] ghci> length (map (/ 2) [0,2..5]) 4 Could you please explain why map may return more elements then it was? Thank you! It's due to the implementation of Enum for Float and Double : > [0,2..5] :

Converting sets of integers into ranges

非 Y 不嫁゛ 提交于 2019-12-01 17:06:31
What's the most idiomatic way to convert a set of integers into a set of ranges? E.g. given the set {0, 1, 2, 3, 4, 7, 8, 9, 11} I want to get { {0,4}, {7,9}, {11,11} }. Let's say we are converting from std::set<int> into std::vector<std::pair<int, int>> . I treat Ranges as inclusive on both sides, since it's more convenient in my case, but I can work with open-ended ranges too if necessary. I've written the following function, but I feel like reinventing the wheel. Please tell maybe there's something in STL or boost for this. typedef std::pair<int, int> Range; void setToRanges(const std::set

Normalizing feature values for SVM

冷暖自知 提交于 2019-12-01 16:54:24
I've been playing with some SVM implementations and I am wondering - what is the best way to normalize feature values to fit into one range? (from 0 to 1) Let's suppose I have 3 features with values in ranges of: 3 - 5. 0.02 - 0.05 10-15. How do I convert all of those values into range of [0,1]? What If, during training, the highest value of feature number 1 that I will encounter is 5 and after I begin to use my model on much bigger datasets, I will stumble upon values as high as 7? Then in the converted range, it would exceed 1... How do I normalize values during training to account for the

Dictionary with range as key

江枫思渺然 提交于 2019-12-01 16:31:06
In Python, how can I map from a range of values to one concrete value? Basically, I want a dictionary, which I can fill with ranges and index with numbers: rd = rangedict() rd[(0, 10)] = 5 print rd[4] # prints 5 print rd[6] # prints 5 rd[(5, 15)] = 20 print rd[4] # prints 5 print rd[6] # prints 20 You could use an interval tree pip install intervaltree from intervaltree import Interval, IntervalTree rd = IntervalTree() rd[0:10] = 5 print rd[4] print rd[5] https://pypi.python.org/pypi/intervaltree Thanks to the comments I could find a solution using the intervaltree package. from intervaltree

Convert entire range to lowercase without looping through cells Indirect

天涯浪子 提交于 2019-12-01 16:07:08
I'm looking at VBA code that takes an entire range of cells and converts them into lowercase. I found the following: [A1:A20] = [index(lower(A1:A20),)] This works fine for a fixed range (don't entirely understand syntax, but found the following post:) Post detailing code above My problem is this: I would like to be able to set the range dynamically as I'm dealing with changing range sizes. However, the following doesn't work, and I can't seem to be able to use INDIRECT() either in VBA. Range("A1:A" & n) = [index(lower(Range("A1:A" & n)),)] Is there a way to make this work? I would really like

Why does map return an additional element when using ranges in Haskell?

半腔热情 提交于 2019-12-01 15:57:45
问题 I've just started learning Haskell and found a strange thing. Let we have a list: ghci> [0,2..5] [0,2,4] It has 3 elements. When I use map with this list I get 3 element as output, for example: ghci> map (+ 1) [0,2..5] [1,3,5] ghci> map (* 2) [0,2..5] [0,4,8] ghci> map (`div` 2) [0,2..5] [0,1,2] But when I use fractional division I get 4 elements in output list: ghci> map (/ 2) [0,2..5] [0.0,1.0,2.0,3.0] ghci> length (map (/ 2) [0,2..5]) 4 Could you please explain why map may return more

Blocking multiple ip ranges using mod access in htaccess

烈酒焚心 提交于 2019-12-01 15:56:06
I read the guide from apache site but I'm a bit confused, I'm trying to ban some ranges using this syntax: order allow,deny deny from 127.0.55.0/127.0.75.255 deny from 127.0.235.0/127.0.255.255 allow from all But I think it's not working properly, probably the syntax is wrong or I'm using it in the wrong way, where should I write this text in htaccess? before the other lines or after? in the same htaccess file there're some mod rewrite script too (for anti-hotlinking). I've come to this answer using apache documentation . You can give an address range using ip/netmask pair : deny from 127.0.55

Convert entire range to lowercase without looping through cells Indirect

最后都变了- 提交于 2019-12-01 15:27:21
问题 I'm looking at VBA code that takes an entire range of cells and converts them into lowercase. I found the following: [A1:A20] = [index(lower(A1:A20),)] This works fine for a fixed range (don't entirely understand syntax, but found the following post:) Post detailing code above My problem is this: I would like to be able to set the range dynamically as I'm dealing with changing range sizes. However, the following doesn't work, and I can't seem to be able to use INDIRECT() either in VBA. Range(

matlab: dividing vector into overlapping chunks of fixed size

杀马特。学长 韩版系。学妹 提交于 2019-12-01 15:11:08
问题 I've a vector that I would like to split into overlapping subvectors of size cs in shifts of sh . Imagine the input vector is: v=[1 2 3 4 5 6 7 8 9 10 11 12 13]; % A=[1:13] given a chunksize of 4 ( cs=4 ) and shift of 2 ( sh=2 ), the result should look like: [1 2 3 4] [3 4 5 6] [5 6 7 8] [7 8 9 10] [9 10 11 12] note that the input vector is not necessarily divisible by the chunksize and therefore some subvectors are discarded. Is there any fast way to compute that, without the need of using e

Select from a range but exclude certain numbers [duplicate]

六眼飞鱼酱① 提交于 2019-12-01 14:34:12
问题 This question already has answers here : How to get a random number from a range, excluding some values (8 answers) Closed 5 years ago . Is it possible to pick a random number from a given range (1-90), but exclude certain numbers. The excluded numbers are dynamically created but lets say they are 3, 8, and 80. I have managed to create random number generator but couldn't identify any functions that let me fulfill my requirements. Random r = new Random(); this.num = r.Next(1, 90); The numbers