I have been playing around with ray-casting and decided to use 3D arrays to make levels, However TCC spits out this:
M_MAIN.C:19: error: index too large
Is there a limit to how large an array can be?
Code:
#define MAP_01_WIDTH 8
#define MAP_01_HEIGHT 8
#define MAP_01_DEPTH 8
#define MAP_01_PLAYER_START_X 2
#define MAP_01_PLAYER_START_Y 2
#define MAP_01_PLAYER_START_Z 2
char MAP_01[MAP_01_WIDTH][MAP_01_DEPTH][MAP_01_HEIGHT] =
{
{ {1, 1, 1, 1, 1, 1, 1, 1}, {1, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 1}, {1, 1, 1, 1, 1, 1, 1, 1} },
{ {1, 0, 0, 0, 0, 0, 0, 1}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {1, 0, 0, 0, 0, 0, 0, 1} },
{ {1, 0, 0, 0, 0, 0, 0, 1}, {2, 0, 3, 0, 0, 4, 0, 2}, {2, 0, 3, 0, 0, 4, 0, 2}, {2, 0, 3, 0, 0, 4, 0, 2}, {2, 0, 3, 0, 0, 4, 0, 2}, {2, 0, 3, 0, 0, 4, 0, 2}, {2, 0, 3, 0, 0, 4, 0, 2}, {1, 0, 0, 0, 0, 0, 0, 1} },
{ {1, 0, 0, 0, 0, 0, 0, 1}, {2, 0, 3, 0, 0, 4, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 3, 0, 0, 4, 0, 2}, {1, 0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, 1, 1, 1} }
};
You define the array with size 8x8x8 but initializing it with 9x8x8 elements. Fix the size with:
#define MAP_01_WIDTH 9
Or better yet, let the compiler calculate that:
char MAP_01[][MAP_01_DEPTH][MAP_01_HEIGHT] = {...};
Related
I have a 2D extern array "the_board[17][25]". I am fairly new to C and believe I have some linking issue. in my board.c file I initialized the board, giving every cell a value. when calling the board in my other functions, the values change, even though I have made no edits to the array since initializing it.
header file to declared array:
#define BOARD_SIZE_X 25
#define BOARD_SIZE_Y 17
extern int the_board[BOARD_SIZE_Y][BOARD_SIZE_X];
#define DA 0 /* disallowed */
#define RE 1 /* red */
#define GR 2 /* green */
#define EM 7 /* empty */
board.c file containing initialization:
#include "my_header.h"
int the_board[BOARD_SIZE_Y][BOARD_SIZE_X] = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7},
{0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0},
{0, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 0},
{0, 0, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 0, 0},
{0, 0, 0, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 0, 0, 0},
{0, 0, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 0, 0},
{0, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 0},
{0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0},
{7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
};
Sorry for the large block of code it has to be manually defined. This is where the problem I run into. When calling the_board[][], the values become screwed up. For an example this is what happens when I print the_board[BOARD_SIZE_Y][BOARD_SIZE_X] in main.c:
img of array: https://i.stack.imgur.com/KLQqT.png
#include "my_header.h"
int main() {
int i, j;
int the_board[BOARD_SIZE_Y][BOARD_SIZE_X];
for (i = 0; i < BOARD_SIZE_Y; i++){
for (j = 0; j < BOARD_SIZE_X; j++) {
printf(" %d ", the_board[i][j]);
}
}
return 0;
}
You have one initialised global the_board, defined in board.c.
You have one non-initialised local the_board defined inside main().
That second one hides the first one.
Delete the line which defines it, i.e.
int the_board[BOARD_SIZE_Y][BOARD_SIZE_X];
def create_zero_matrix(n,m):
return [[0 for i in range(m)] for j in range(n)]
def m_tight_print(m):
for i in range(len(m)):
line = ''
for j in range(len(m[0])):
line += str(m[i][j])
print(line)
def pd_map(r,c,sites):
blank = create_zero_matrix(r,c)
for count, site in enumerate(sites):
blank[site[0]][site[1]] = count #locating the shops
Hello, how do I calculate the distance of every point in my matrix from a specific point such as [1,3] (point 0) or [4,7] (point 1) or [7,2] (point 2) and change that particular value such that it shows the point that is closest to that particular coordinate?
>>> pprint(pizzaMap)
[[0, 0, 0, 0, 0, 0, 0, 'X', 1, 1]
[0, 0, 0, 0, 0, 0, 0, 1, 1, 1]
[0, 0, 0, 0, 0, 0, 0, 1, 1, 1]
[0, 0, 0, 0, 0, 0, 'X', 1, 1, 1]
['X', 0, 0, 0, 0, 0, 1, 1, 1, 1]
[2, 2, 2, 2, 2, 'X', 1, 1, 1, 1]
[2, 2, 2, 2, 2, 2, 1, 1, 1, 1]
[2, 2, 2, 2, 2, 2, 2, 1, 1, 1]
[2, 2, 2, 2, 2, 2, 2, 1, 1, 1]
[2, 2, 2, 2, 2, 2, 2, 'X', 1, 1]]
This above is the test case but I can only get this from my code.
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 2, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
```.
I tried to use numpy.argwhere() but in the end I could not do it. What code must I use such that I am able to get my test case?
l have 5 adjacency matrices (nump arrays) : A, B, C, D, E. each of dimension [20,20].
Given A, B, C, D, E, l would like to build F which stacks the 5 adjacency matrices. Since we have 5 2D arrays of [20,20] then F is of dimension [20*5,20*5] as follow :
F=np.zeros((100,100))
F=[
[A,0,0,0,...,0],
[0,...,B,...,0],
[0,...,..,C,0],
[0,.........D,..,0],
[0,...........,E],
]
such that :
A is indexed at F[0][:20]
B is indexed at F[1][20:40]
C is indexed at F[2][40:60]
D is indexed at F[3][60:80]
E is indexed at F[4][80:100]
What is the efficient numpy way to do that for larage number of adjacency matrices ?. Let's, we have n adjacency matrices to stack in a diagonal of new 2D array of [n*20,n*20]
You could use scipy.sparse.block_diag:
>>> AtoE = np.add.outer(np.arange(5, 10), np.zeros((3, 3), int))
>>> scipy.sparse.block_diag(AtoE).A
array([[5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 7, 7, 7, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 7, 7, 7, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 7, 7, 7, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 9],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 9],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 9]], dtype=int64)
Sparse storage may be a good idea, anyway.
Alternatively, here is a more direct method in case you definitely want to use dense arrays:
>>> A = AtoE[0]
>>> N, N = A.shape
>>> k = len(AtoE)
>>> out = np.zeros((k, N, k, N), A.dtype)
>>> np.einsum('ijik->ijk', out)[...] = AtoE
>>> out.reshape(k*N, k*N)
array([[5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 7, 7, 7, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 7, 7, 7, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 7, 7, 7, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 9],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 9],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 9]])
I have a file. Inside the file I have stored a two-dimensional array, something like this:
[[0, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 1, 1, 0, 0], [0, 0, 0, 0, 1, 1, 1, 1, 0, 0], [0, 0, 0, 1, 0, 0, 1, 0, 0, 0], [0, 1, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 1, 1, 0], [0, 1, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 1, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
Lengths of arrays can vary and they are not always 10 elements long.
I read the array from the file using this method:
map = IO.readlines("test.txt")
and when i print the result using:
map.each {|x| puts "#{x}"}
the output is what I expect it to be. But if I try to get the row length using:
puts map[0].length
I get 320 instead of 10 (which is what I expect).
Can someone explain me why am I getting 320 instead of 10 ?
Instead of IO#readlines you should use JSON#parse since it’s a valid json:
require 'json'
JSON.parse(File.read("test.txt"))
#⇒ [[0, 0, 1, 0, 1, 0, 1, 0, 1, 0],
# [0, 0, 0, 0, 0, 0, 1, 1, 0, 0],
# [0, 0, 0, 0, 1, 1, 1, 1, 0, 0],
# [0, 0, 0, 1, 0, 0, 1, 0, 0, 0],
# [0, 1, 1, 0, 0, 0, 0, 0, 0, 0],
# [0, 0, 0, 0, 0, 0, 1, 1, 1, 0],
# [0, 1, 1, 0, 1, 0, 1, 0, 1, 0],
# [0, 1, 0, 0, 0, 0, 0, 1, 0, 0],
# [0, 0, 0, 1, 0, 0, 0, 1, 0, 0],
# [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
I am working on a multilevel differential item functioning model using WinBUGS package. I have successfully built simpler models, but I have also gotten the error "array index is less than one". I'd be very pleased if you could help.
# Model
Model
{
for (l in 1:50){
y[l] ~ dbern(p[l])
logit(p[l])<- u2[stu[l]] - beta[x[l]] + gamma[tea[l], x[l]]*grp[l] + alpha1[x[l]]*geo[l] +
alpha2[x[l]]*conf[l] + alpha3[x[l]]*ses[l]
}
for (t in 1:10){
for (i in 1:10){
gamma[t,i] ~ dnorm(gamma.hat[t,i], tau.gamma[i])
gamma.hat[t,i]<-pi1[i] + pi2[i]*inq[t]
}
}
# fixed effect prior
for (i in 1:10){
beta[i] ~ dnorm(0, .0001)
alpha1[i] ~ dnorm(0, .0001)
alpha2[i] ~ dnorm(0, .0001)
alpha3[i] ~ dnorm(0, .0001)
pi1[i] ~ dnorm(0, .0001)
pi2[i] ~ dnorm(0, .0001)
}
# Random effect prior
for (s in 1:5){
u2[s] ~ dnorm(0,tau.u2)
}
tau.u2 <- pow(sigma.u2, -2)
sigma.u2 ~ dunif (0, 100)
for (i in 1:10){
tau.gamma[i] <- pow(sigma.gamma[i],-2)
sigma.gamma[i] ~ dunif(0,100)
}
}
# Data
list(y=c(0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0), ses=c(0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1), conf=c(1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1), geo=c(1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1), grp=c(1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0,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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), .Dim=c(10, 10)))
Indexes start from 1, not 0, in BUGS. The variables stu and tea are used for indexing, but they take the values 0,1 - they should be 1,2 instead.
Something going on with x. It is one shorter in length than the other variables, perhaps you are missing an observation.