does lack of type declarations make Python unsafe?
mirko-lists at zeibig.net
Wed Jun 18 11:45:49 CEST 2003
beliavsky at aol.com wrote:
> The beginning of the following Fortran 95 subroutine, for example,
> provides useful information both to the compiler and to a programmer
> trying to understand what it does:
> subroutine solve_lsq_svd_rmse(aa,bb,xx,rmse,ierr)
> ! solve a set of least-squares linear equations and compute the rmse
> real , intent(in) :: aa(:,:) ! matrix of independent variables
> real , intent(in) :: bb(:) ! vector of dependent variable
> real , intent(out) :: xx(:) ! solution of least-squares problem
> real , intent(out) :: rmse ! rmse of regression
> integer , intent(out) :: ierr ! error flag
> In Python, to ensure that aa is a 2-D array and that bb and xx are 1-D
> arrays, you need to write some checking code, which will not be as
> clear as the above declarations IMO. Even if you do this, the errors
> will be caught at run time, not compile time.
What about using the array-module for this?
from import array
aa = [array('d', aa), array('d', aa)] # matrix of independent variables
bb = array('d', bb) # vector of dependent variable
xx = array('d') # solution of least-squares problem
More information about the Python-list