コード例 #1
0
def i4_width ( i ):

#*****************************************************************************80
#
## I4_WIDTH returns the "width" of an I4.
#
#  Example:
#
#        I  VALUE
#    -----  -------
#    -1234    5
#     -123    4
#      -12    3
#       -1    2
#        0    1
#        1    1
#       12    2
#      123    3
#     1234    4
#    12345    5
#
#  Discussion:
#
#    The width of an integer is the number of characters necessary to print it.
#
#    The width of an integer can be useful when setting the appropriate output
#    format for a vector or array of values.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    09 May 2013
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, integer I, the number whose width is desired.
#
#    Output, integer VALUE, the number of characters necessary to represent
#    the integer in base 10, including a negative sign if necessary.
#
  from i4_log_10 import i4_log_10

  if ( 0 <= i ):
    value = i4_log_10 ( i ) + 1
  else:
    value = i4_log_10 ( i ) + 2
 
  return value
コード例 #2
0
def r8mat_indicator ( m, n ):

#*****************************************************************************80
#
## R8MAT_INDICATOR sets up an indicator R8MAT.
#
#  Discussion:
#
#    The value of each entry suggests its location, as in:
#
#      11  12  13  14
#      21  22  23  24
#      31  32  33  34
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    03 December 2014
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, integer M, the number of rows of the matrix.
#    M must be positive.
#
#    Input, integer N, the number of columns of the matrix.
#    N must be positive.
#
#    Output, real TABLE(M,N), the indicator table.
#
  import numpy as np
  from i4_log_10 import i4_log_10

  table = np.zeros ( ( m, n ), dtype = np.float64 )

  fac = 10 ** ( i4_log_10 ( n ) + 1 )

  for i in range ( 0, m ):
    for j in range ( 0, n ):
      table[i,j] = fac * ( i + 1 ) + ( j + 1 )

  return table