infinity

-Inf in colormap — low in MATLAB, high in Python?

*爱你&永不变心* 提交于 2019-12-10 17:47:57
问题 I've ported some MATLAB code to Python, including a plotting utility that plots a colormap of some data in a 2D matrix (list). MATLAB and Python plotting utilities are pretty similar, so I am able to make them match quite closely visually, with little effort. The test matrix that I'm using here is: X = [ 1 0 3 ] [ 4 5 6 ] [ 7 8 9 ] MATLAB with test matrix X = [1 0 3; 4 5 6; 7 8 9]; figure(1); imagesc(X); colormap(hot); colorbar; Python with test matrix import numpy as np import matplotlib as

How to produce infinity in Haskell?

不羁的心 提交于 2019-12-10 17:29:17
问题 Similarily to How to produce a NaN in Haskell ... In C, there is the INFINITY macro, defined by math.h . Again, in http://hackage.haskell.org/package/ClassyPrelude-0.1/docs/Prelude-Math.html I can see falicities to test for infnity, but not to produce one. Therefore, is my only choice something like 1/0 ? 回答1: The iee754 package has functions and constants specific to that floating point format. In particular, it has the Numeric.IEEE.infinity constant for members for the IEEE class (which

how can I pass infinity to redis from python?

佐手、 提交于 2019-12-10 15:29:36
问题 I'm using redis-py and want to use -inf and inf with ZRANGEBYSCORE. I tried to do this using string and float of inf but those return an empty set. How can I do this? EDIT I tried doing the following command: redis.StrictRedis.ZRANGEBYSCORE("SORTEDSET", "-inf", "inf") or redis.StrictRedis.ZRANGEBYSCORE("SORTEDSET", float("-inf"), float("inf")) UPDATE My error was that my abstraction for zrangebyscore was using zrange by mistake...inf works as stated below. 回答1: This is my code has been tested

Is there an inf constant in Perl?

十年热恋 提交于 2019-12-10 12:29:17
问题 I'm initialising a list with infinities for an algorithm. Writing $x = 9**9**9 feels unintuitive, and also, I might want to use BigInt in the future. 1/0 throws an error. What's the canonical way to get inf ? 回答1: You can use the special string "inf" : perl -E'say "inf" + 1' inf perl -E'say 1 / "inf"' 0 et cetera. Other special strings include +inf , -inf , nan . Of course this also works with bignum or bigint pragmas. However, these pragmas export equivalent functions inf and NaN so that you

How can I make array B from array A without infinities included in Python 2.7?

為{幸葍}努か 提交于 2019-12-10 12:23:18
问题 Array A looks like this: [1, -inf, 2, 3, inf, -60.2] Array B should look like this: [1, 2, 3, -60.2] How can I make array B from array A without infinities included in Python 2.7? 回答1: B = filter(lambda x: abs(x) != float('inf'), A) 回答2: B = [x for x in A if not math.isinf(x)] 回答3: Did you mean: >>> inf = float('inf'); >>> import math >>> print filter(lambda x: not math.isinf(x), [1, -inf, 2, 3, inf, -60.2]) [1, 2, 3, -60.200000000000003] ? 回答4: The easiest one: arrayA = [1, float('-inf'), 2,

Infinity in MSVC++

╄→尐↘猪︶ㄣ 提交于 2019-12-10 03:28:49
问题 I'm using MSVC++, and I want to use the special value INFINITY in my code. What's the byte pattern or constant to use in MSVC++ for infinity? Why does 1.0f/0.0f appear to have the value 0? #include <stdio.h> #include <limits.h> int main() { float zero = 0.0f ; float inf = 1.0f/zero ; printf( "%f\n", inf ) ; // 1.#INF00 printf( "%x\n", inf ) ; // why is this 0? printf( "%f\n", zero ) ; // 0.000000 printf( "%x\n", zero ) ; // 0 } 回答1: Use numeric_limits: #include <limits> float maxFloat = std:

Force JSON.stringify() to emit NaN / Infinity or JS JSON lib that does so

百般思念 提交于 2019-12-09 13:29:56
问题 I'm looking into the feasibility of adding NaN/Infinity support to a pre-existing scientific application that uses JSONRPC for client/server interactions. Many JSON libs do handle (optionally in some cases) NaNs and Infs, for example: Python json reads and writes Java Jackson reads but writes strings instead of barewords Java GSON reads and writes Javascript can read I'm aware that NaN and Infinity are not supported in the JSON spec, and am aware of the related questions. However, AFAICT the

O-notation, O(∞) = O(1)?

筅森魡賤 提交于 2019-12-09 02:49:44
问题 So a quick thought; Could one argue that O(∞) is actually O(1)? I mean it isn't depend on input size? So in some way its, constant, even though it infinity. Or is the only 'correct' way to express it O(∞)? 回答1: Infinity is not a number, or at least not a real number, so the expression is malformed. The correct way to express this is to simply state that a program doesn't terminate. Note: program , not algorithm , as an algorithm is guaranteed to terminate. (If you wanted, you might be able to

Python integer infinity for slicing

喜你入骨 提交于 2019-12-08 15:48:53
问题 I have defined a slicing parameter in a config file: max_items = 10 My class slices a list according to this parameter: items=l[:config.max_itmes] When max_items = 0 , I want all items to be taken from l . The quick and dirty way is: config.max_items=config.max_items if config.max_items>0 else 1e7 Assuming that there will be less then 1e7 items. However, I don't fancy using magic numbers. Is there a more Pythonic way of doing it, like an infinity integer constant? 回答1: There is no "infinity

How to represent integer infinity?

孤街醉人 提交于 2019-12-06 18:20:22
问题 I need a way to represent an integer number that can be infinite. I'd prefer not to use a floating point type (double.PositiveInfinity) since the number can never be fractional and this might make the API confusing. What is the best way to do this? Edit: One idea I haven't seen yet is using int? with null representing infinity. Are there any good reasons not to do this? 回答1: If you don't need the full range of integer values, you can use the int.MaxValue and int.MinValue constants to