Skip to content

Tag: python

Slicing a 3D image to create a 2D image

I have several 3D images of shape (32,32,32) and I want to create 2D images from them. I want to do that by getting each slice in the z-axis and putting each of them in a square array in order, something like this: Because I want the 2D image to be square I need to fill the missing slices with

Is urlopen lazily evaluated?

Would the following only fetch the headers or would it fetch the whole document? I’m using this to check if it is or not an html page, to avoid downloading (big) files. Answer It appears that only the headers and a bit of the body is retrieved in the urlopen() call, and the rest is gotten upon the read(…

compute mean from several years using xarray

I want to compute the mean for an xarray dataset that contains daily temperature data from 2015-2020. Here is what I am doing currently: ds.groupby(‘time.year’).mean(‘time’) However, this gives me annual mean for each year separately, whereas I want the mean for all the years. How do I…

Iterating through list of lists of lists

I am trying to iterate through a 3-D list in python(not numpy but I am willing to convert to a numpy array if this makes it easier) in such a way that from a list like this: I can get the output I can’t figure out how to make it iterate like this… My code: I’ve tried different things but

How to format query results as CSV?

My goal: Automate the operation of executing a query and output the results into a csv. I have been successful in obtaining the query results using Python (this is my first project ever in Python). I am trying to format these results as a csv but am completely lost. It’s basically just creating 2 massiv…