Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'explicitly': 0.05; 'friday,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'dark.': 0.16; 'numpy': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:Problem': 0.16; 'typeerror:': 0.16; 'thanks,': 0.17; 'wrote:': 0.18; 'library': 0.18; 'print': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'script': 0.25; 'post': 0.26; 'code:': 0.26; 'header:X-Complaints- To:1': 0.27; 'array': 0.29; "i'm": 0.30; 'getting': 0.31; 'assert': 0.31; 'says': 0.33; 'minimal': 0.33; 'skip:t 40': 0.33; 'problem': 0.35; 'subject:with': 0.35; 'skip:s 30': 0.35; 'but': 0.35; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'changed': 0.39; 'received:org': 0.40; 'according': 0.40; 'skip:n 10': 0.64; 'here': 0.66; '20,': 0.68; 'otten': 0.84; 'replicate': 0.84; 'cast': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Problem with numpy 2D Histogram Date: Fri, 20 Jun 2014 14:30:32 +0200 Organization: None References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p57bd80d2.dip0.t-ipconnect.de User-Agent: KNode/4.11.5 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 61 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1403267450 news.xs4all.nl 2835 [2001:888:2000:d::a6]:36070 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:73454 Jamie Mitchell wrote: > On Friday, June 20, 2014 12:00:15 PM UTC+1, Peter Otten wrote: >> Jamie Mitchell wrote: >> >> >> >> > I have changed my x and y data to float64 types but I am still getting >> > the >> >> > same error message? >> >> >> >> Please double-check by adding >> >> >> >> assert x.dtype == np.float64 >> >> assert y.dtype == np.float64 >> >> >> >> If none of these assertions fail try to make a minimal script including >> some >> >> data that provokes the TypeError and post it here. > > OK this is my code: > > swh_Q0_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q0/swh/controlperiod/south_west/swhcontrol_swest_annavg.nc','r') > hs_Q0_con_sw=swh_Q0_con_sw.variables['hs'][:] > x=hs_Q0_con_sw.astype(float64) > # When I print the dtype of x here it says 'float64' > mwp_Q0_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q0/mean_wave_period/south_west/controlperiod/mwpcontrol_swest_annavg1D.nc','r') > te_Q0_con_sw=mwp_Q0_con_sw.variables['te'][:] > y=te_Q0_con_sw.astype(float64) > If I try assert x.dtype == np.float64 I get: > AssertionError That means the dtype is not np.float64. As I have neither the data nor the netCDF4 library to replicate your problem I'm out. What you might try is to construct a numpy array explicitly x = np.array([float(v) for v in swh_Q0_con_sw.variables["hs"]]) but that's just a stab in the dark. > hist,xedges,yedges=np.histogram2d(x,y,bins=10) > TypeError: Cannot cast array data from dtype('O') to dtype('float64') > according to the rule 'safe' > > Thanks, > > Jamie