Try to search your question here, if you can't find : Ask Any Question Now ?

How fix valueerror when using reshape function in python

HomeCategory: stackoverflowHow fix valueerror when using reshape function in python
Avatarrupesh asked 3 months ago

I am trying to extract chlorophyll from a monthly averaged chl .nc satellite file (processed L2 to L3 product) which has geographic boundary coordinates latitude -25 S to -12 N and longitude -179 W to -169 E and there 1443*1110 floating point array elements. I have to write a python code that will let me input my latitude and longitude and python will print out the corresponding chl value found in that location.

Here are starting lines of my code and the error is in reshape lines.

#!/usr/bin/env python

import numpy as np
import pylab

#input user's selection of latitudes and longitudes points

lat = float(input('enter your latitude here: '))
print 'lat: ',lat
lon = float(input('enter your longitude here: '))
print 'lon: ',lon 

#Call path directory, call file name, call variable 'fromfile'

path = '/home/rst/data/final_data/2002_chl_sst/Jul/Output-L3/monthly /1000m-chlor_a/mean/'
fname = open(path) 
chl = np.fromfile(fname, dtype=np.float64) 

#reshape the data into 2D matrix array

nrow = 1443.0
ncol = 1110.0
chl = chl.reshape([nrow,ncol])      # this is line 21
print chl.shape

It’s the first error in my code, the rest of my code is not shown here. What is the total of this new array ? Appreciate any help, thanks

Traceback (most recent call last):
File “”, line 21, in
chl = chl.reshape([nrow,ncol])
ValueError: total size of new array must be unchanged

1 Answers
Best Answer
AvatarFernando answered 3 months ago
Your Answer

5 + 0 =

Popular Tags

WP Facebook Auto Publish Powered By :