infinite

What's exactly happening in infinite nested lists?

浪子不回头ぞ 提交于 2019-11-27 05:28:20
问题 It's possible to create an infinite nested list in Python. That's clear and, although not popular and definitely not useful is a known fact. >>> a = [0] >>> a[0] = a >>> a [[...]] >>> a[0] == a True My question is, what is happening here: >>> a = [0] >>> b = [0] >>> a[0], b[0] = b, a >>> a [[[...]]] >>> b [[[...]]] >>> a == b Traceback (most recent call last): File "<stdin>", line 1, in <module> RuntimeError: maximum recursion depth exceeded in cmp >>> a[0] == b True >>> a[0][0] == b

CSS3 filter

北城以北 提交于 2019-11-27 03:16:48
filter:定义了元素的可视效果 具体函数: hue-rotate() 色相旋转 blur() 高斯模糊效果 brightness() 图片变亮 contrast() 图像的对比度 grayscale() 灰度 invert()反转 opacity() 透明度 saturate() 饱和度 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>CSS3 filter</title> </head> <style type="text/css"> body,html{ display: flex; align-items:center; justify-content:center; width: 100%; height: 100%; background: linear-gradient(#E0FFFF 0, #696969 100%); margin:0; } .wrap{ display: flex; flex-wrap: wrap; } .wrap div{ width: 15vw; height:15vw; margin:10px; border-radius: 50%; background: linear-gradient(#FFFFF0 0, #F0E68C 25%,

Adding wheel factorization to an indefinite sieve

只谈情不闲聊 提交于 2019-11-27 02:21:38
I’m modifying an indefinite sieve of Eratosthenes from here so it uses wheel factorization to skip more composites than its current form of just checking all odds. I’ve worked out how to generate the steps to take to reach all the gaps along the wheel. From there I figured I could just substitute the +2’s for these wheel steps but it’s causing the sieve to skip primes. Here's the code: from itertools import count, cycle def dvprm(end): "finds primes by trial division. returns a list" primes=[2] for i in range(3, end+1, 2): if all(map(lambda x:i%x, primes)): primes.append(i) return primes def

Is there a standard class for an infinitely nested defaultdict?

走远了吗. 提交于 2019-11-27 02:17:40
问题 Does anyone know if there's a standard class for an infinitely nestable dictionary in Python? I'm finding myself repeating this pattern: d = defaultdict(lambda: defaultdict(lambda: defaultdict(int))) d['abc']['def']['xyz'] += 1 If I want to add "another layer" (e.g. d['abc']['def']['xyz']['wrt'] ), I have to define another nesting of defaultdicts. To generalize this pattern, I've written a simple class that overrides __getitem__ to automatically create the next nested dictionary. e.g. d =

Android: How can I stop an infinite animation applied on an ImageView?

你说的曾经没有我的故事 提交于 2019-11-27 02:04:42
问题 I have an ImageView on which I have applied a rotate animation. Since I want the rotation to go on continuously, I gave the repeatCount as infinite in my rotate.xml: android:repeatCount="infinite" In onCreate(), I load the animation and start it. Animation myAnim = AnimationUtils.loadAnimation(this, R.anim.rotate); objectImg.startAnimation(myAnim); When a button is pressed, the rotation must stop. Hence in my onClick(), I called clearAnimation(). objectImg.startAnimation(myAnim); My simple

Python's xrange alternative for R OR how to loop over large dataset lazilly?

牧云@^-^@ 提交于 2019-11-27 01:56:43
Following example is based on discussion about using expand.grid with large data. As you can see it ends up with error. I guess this is due to possible combinations which is according to mentioned page 68.7 billions: > v1 <- c(1:8) > v2 <- c(1:8) > v3 <- c(1:8) > v4 <- c(1:8) > v5 <- c(1:8) > v6 <- c(1:8) > v7 <- c(1:8) > v8 <- c(1:8) > v9 <- c(1:8) > v10 <- c(1:8) > v11 <- c(1:8) > v12 <- c(1:8) > expand.grid(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12) Error in rep.int(rep.int(seq_len(nx), rep.int(rep.fac, nx)), orep) : invalid 'times' value In addition: Warning message: In rep.int(rep

Left and Right Folding over an Infinite list

泄露秘密 提交于 2019-11-27 00:02:37
问题 I have issues with the following passage from Learn You A Haskell (Great book imo, not dissing it): One big difference is that right folds work on infinite lists, whereas left ones don't! To put it plainly, if you take an infinite list at some point and you fold it up from the right, you'll eventually reach the beginning of the list. However, if you take an infinite list at a point and you try to fold it up from the left, you'll never reach an end! I just don't get this. If you take an

Haskell infinite recursion

血红的双手。 提交于 2019-11-26 17:21:00
问题 The following function computes the Fibonacci sequence: fib = 0 : 1 : (zipWith (+) fib (tail fib)) If we run it, we will get an infinite list, but how does the recursion work? Why does it get to print numbers on the screen if it the function keeps calling itself? I would appreciate if you could explain how the compiler manages the calls. 回答1: I've drawn a picture, which you might find helpful. Note that zipWtih op (x:xs) (y:xs) = (op x y):zipWith xs ys , which is how zipWtih appears to "move"

How can I represent an infinite number in Python?

此生再无相见时 提交于 2019-11-26 14:58:23
问题 How can I represent an infinite number in python? No matter which number you enter in the program, no number should be greater than this representation of infinity. 回答1: In Python, you can do: test = float("inf") In Python 3.5, you can do: import math test = math.inf And then: test > 1 test > 10000 test > x Will always be true. Unless of course, as pointed out, x is also infinity or "nan" ("not a number"). Additionally (Python 2.x ONLY), in a comparison to Ellipsis , float(inf) is lesser, e.g

Using Tumblr Like Button with Infinite Scroll

ぐ巨炮叔叔 提交于 2019-11-26 14:25:27
问题 I'm trying to use the new Tumblr like buttons within Infinite Scroll (allowing your theme a like button on individual Tumblr posts from the homepage) they work for the first 15 posts of the first 'page' but then as soon as it loads another page the like button stops working. These are the instructions given from Tumblr on the Docs page: Function: Tumblr.LikeButton.get_status_by_page(n) Description: Call this function after requesting a new page of Posts. Takes the page number that was just