With matplotlib when a log scale is specified for an axis, the default method of labeling that axis is with numbers that are 10 to a power eg. 10^6. Is there an easy way to change all of these labels to be their full numerical representation? eg. 1, 10, 100, etc. Note that I do not know what the range
Tag: numpy
RuntimeWarning: divide by zero encountered in log
I am using numpy.log10 to calculate the log of an array of probability values. There are some zeros in the array, and I am trying to get around it using However, RuntimeWarning: divide by zero encountered in log10 still appeared and I am sure it is this line caused the warning. Although my problem is solved, I am confused why
How to do linear regression, taking errorbars into account?
I am doing a computer simulation for some physical system of finite size, and after this I am doing extrapolation to the infinity (Thermodynamic limit). Some theory says that data should scale linearly with system size, so I am doing linear regression. The data I have is noisy, but for each data point I can estimate errorbars. So, for example
How to split a pandas time-series by NAN values
I have a pandas TimeSeries which looks like this: I would like split the pandas TimeSeries everytime there occurs one or more NaN values in a row. The goal is that I have separated events. I could loop through every row but is there also a smart way of doing that??? Answer You can use numpy.split and then filter the
Remove rows in 3D numpy array
I need to remove some rows from a 3D numpy array. For exampe: and I want to remove the third row of both pages of the matrix in order to obtain something like: I have tried with but I can’t obtain what I need. Answer axis should 1.
how to translate matlab function max(y(x>3)>2) to numpy in single line
i want to convert matlab functions like all, any, max min to numpy. since these functions takes compound expressions as inputs, wanted to know how to achive the same in numpy. for ex. max(y(x>3)>2) in matlab i would have got the answer as 9 how can i write the above max function in numpy so that it accepts the diffrent
In Python NumPy what is a dimension and axis?
I am coding with Pythons NumPy module. If coordinates of a point in 3D space are described as [1, 2, 1], wouldn’t that be three dimensions, three axis, a rank of three? Or if that is one dimension then shouldn’t it be points (plural), not point? Here is the documentation: In Numpy dimensions are called axes. The number of axes
Index all *except* one item in python
Is there a simple way to index all elements of a list (or array, or whatever) except for a particular index? E.g., mylist[3] will return the item in position 3 milist[~3] will return the whole list except for 3 Answer For a list, you could use a list comp. For example, to make b a copy of a without the
elegant way of convert a numpy array containing datetime.timedelta into seconds in python 2.7
I have a numpy array called dt. Each element is of type datetime.timedelta. For example: how can I convert dt into the array dt_sec which contains only seconds without looping? my current solution (which works, but I don’t like it) is: I tried to use dt.total_seconds() but of course it didn’t work. any idea on how to avoid this loop?
Circular shift of vector (equivalent to numpy.roll)
I have a vector: And I’d like to do something like: Is there a function like that in R? I’ve been googling around, but “R Roll” mostly gives me pages about Spanish pronunciation. Answer How about using head and tail… One cool thing about using head and tail… you get a reverse roll with negative n, e.g.