Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating 2D Array
#1
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
Larz60+ write Nov-23-2020, 08:41 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

Fixed for you this time. Please use code tags on future posts.
Reply
#2
I'd use a Pandas dataframe
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating look up table/matrix from 3d data array chai0404 3 2,825 Apr-09-2020, 04:53 AM
Last Post: buran
  while creating a array using numpy.arrange, how to negate only the last 50 numbers? vicky53 1 2,647 Apr-06-2019, 11:52 AM
Last Post: scidam
  creating an empty NumPy array in Python sandeepatel 2 4,644 Jan-16-2019, 09:24 AM
Last Post: rinu
  Help creating a histogram using an array rubadub 0 2,160 Apr-17-2018, 08:57 PM
Last Post: rubadub
  Creating 2D array without Numpy landlord1984 3 35,732 Jan-28-2017, 01:34 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020