Skip to content
Advertisement

How to define an array without defining its elements?

I want to optimize a problem in Python using scipy.

To achieve this goal:

  1. I define an array of a certain length, but without defining its elements explicitly.

  2. Then, I need to use this array to optimize the problem.

  3. In the last step, I want to print this array as a result.

Here is the simple example:

JavaScript

Advertisement

Answer

Python has following syntax:

JavaScript

it creates an array filled with some_value with provided length

so try:

JavaScript

or if you want to not change the type:

JavaScript

as an alternative use numPy array

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement