Skip to content

Tag: numpy

extracting days from a numpy.timedelta64 value

I am using pandas/python and I have two date time series s1 and s2, that have been generated using the ‘to_datetime’ function on a field of the df containing dates/times. When I subtract s1 from s2 s3 = s2 – s1 I get a series, s3, of type timedelta64[ns] How do I look at 1 element of the ser…

in Numpy, how to zip two 2-D arrays?

For example I have 2 arrays How can I zip a and b so I get ? Answer You can use dstack: If you must have tuples: For Python 3+ you need to expand the zip iterator object. Please note that this is horribly inefficient:

Dropping infinite values from dataframes in pandas?

How do I drop nan, inf, and -inf values from a DataFrame without resetting mode.use_inf_as_null? Can I tell dropna to include inf in its definition of missing values so that the following works? Answer First replace() infs with NaN: and then drop NaNs via dropna(): For example: The same method also works for …

student t confidence interval in python

I am interested in using python to compute a confidence interval from a student t. I am using the StudentTCI() function in Mathematica and now need to code the same function in python http://reference.wolfram.com/mathematica/HypothesisTesting/ref/StudentTCI.html I am not quite sure how to build this function …

how is axis indexed in numpy’s array?

From Numpy’s tutorial, axis can be indexed with integers, like 0 is for column, 1 is for row, but I don’t grasp why they are indexed this way? And How do I figure out each axis’ index when coping with multidimensional array? Answer By definition, the axis number of the dimension is the index…

Puzzled on the ndim from Numpy

Above is my code. the output is: I have checked the page from [here] (Link) I expected a.dim = 2 or 3, but it is 4. Why? Could you give me some hints? Thanks Answer The tuple you give to zeros and other similar functions gives the ‘shape’ of the array (and is available for any array as a.shape). T…

Using arctan / arctan2 to plot a from 0 to 2π

I am trying to replicate a plot in Orbital Mechanics by Curtis, but I just can’t quite get it. However, I have made head way by switching to np.arctan2 from np.arctan. Maybe I am implementing arctan2 incorrectly? In the image below, there are discontinuities popping up. The function is supposed to be sm…