-1

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
  • 2
    The title doesn't seem to match the comment in the method. Commented Sep 18, 2021 at 1:25
  • 2
    How is that function relevant to the question? Commented Sep 18, 2021 at 1:26

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

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

Comments