Python Forum
Creating 2D Array - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: Creating 2D Array (/thread-31097.html)



Creating 2D Array - jpinko - Nov-23-2020

Hi All,

My code is the following:
import numpy
import math
a = numpy.arange(1, 11)
b = numpy.arange(0, .02, .001)
v = []
for c in a:
    v.append([])
    for d in b:
         numpy.append(v[c],(1 / c ** 2) * math.exp( -c ** 2 * math.pi ** 2 * d))
I'm looking to create an a x b array composed of the following:

Output:
a[0]b[0] a[0]b[1] a[0]b[2] etc. a[1]b[0] a[1]b[1] a[1]b[2] etc. a[2]b[0] a[2]b[1] a[2]b[2] etc. etc. etc. etc. etc.
How would I do this? As is my code is producing TypeError: list indices must be integers or slices, not numpy.float64.

Thanks,
Jonathan


RE: Creating 2D Array - jefsummers - Nov-23-2020

I'd use a Pandas dataframe