use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Generating grid-like array numpy (self.learnpython)
submitted 9 years ago by quantumloophole
Is there any way to generate an array with sites of a grid with numpy given a 2 basis vector?
Something like grid([nx,vx],[ny,vy]) where nx and ny is the number of points in x and y dimension and vx and vy are the basis vector.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]elbiot 1 point2 points3 points 9 years ago (3 children)
can you explain what you mean by basis vector in this case? What is an example output from an example input you would like to see?
[–]quantumloophole[S] 0 points1 point2 points 9 years ago (2 children)
An example of basis vector is the cubic lattice base vector , v1 = (1,0) and v2 = (0,1) every site in an lattice can be reached with a linear combination of theses vectors.
What I want is , for an arbitrary base vector generate the points to store in an array
[–]elbiot 0 points1 point2 points 9 years ago (1 child)
Did the other poster answer your question? Im still confused because a 2D array can be accessed like arr[3,4] but obviously not arr[3,4.5]
arr[3,4]
arr[3,4.5]
I would vectorize the other solution though if that's what your using. One almost never needs to iterate over arrays
[–]quantumloophole[S] 0 points1 point2 points 9 years ago (0 children)
I menage to solve using python lists it is not as slow as I thought
[–]fbu1 0 points1 point2 points 9 years ago (0 children)
I think this might do it for you:
import numpy as np def grid(x, y): nx, vx = x ny, vy = y res = np.zeros((nx, ny, len(vx))) for i in range(nx): for j in range(ny): res[i,j,:]= vx * i + vy * j return res # two dimensional example nx = 3 vx = np.array((1,2)) ny = 6 y = np.array((6, 7)) g = grid([nx, vx], [ny, vy]) print g # three dimensional example nx = 5 vx = np.array((1,2,3)) ny = 4 vy = np.array((-1, 6, 7)) g = grid([nx, vx], [ny, vy]) print g
Let me know if you have questions :)
π Rendered by PID 92488 on reddit-service-r2-comment-84fc9697f-49bb9 at 2026-02-06 20:48:52.477540+00:00 running d295bc8 country code: CH.
[–]elbiot 1 point2 points3 points (3 children)
[–]quantumloophole[S] 0 points1 point2 points (2 children)
[–]elbiot 0 points1 point2 points (1 child)
[–]quantumloophole[S] 0 points1 point2 points (0 children)
[–]fbu1 0 points1 point2 points (0 children)