-2

I know in python you can fill an array with 0's using numpy.zeroes(size) but as part of learning I am asked to not use numpy, so my question is, is there a way to fill an array without numpy.zeroes function?

specificly How do I fill the following list with 0's in the following functions?

def myHistWithRescale(listOfNums, maxInt):
    """Givne a list of real numbers in any range, first scale the numbers to
    inters between 0 and maxInt (inclusive), then return the number of occurrences
    of each integer in a list
    """
    rescaledData = rescaleToInt(listOfNums, maxInt)  
    return counts

2 Answers2

2

To create a list of size n of all zeros, just write [0] * n

Frank Yellin
  • 9,127
  • 1
  • 12
  • 22
1

For the function, you can do: arr = [0] * maxInt. Where maxInt is the size of list.
Similarly if you want to fill an array with something other than 0; you can just replace the 0 with any number you want to fill

kevin
  • 286
  • 3
  • 13