Octave: How can I define a symbolic variable of dimension 3? - octave

I have tried this: x=sym(zeros(3,3,2));
But it gives this error message: conversion not supported for arrays of dim > 2
How can I get around this limitation?

Related

I am trying to store twitter trends into a text file but getting errors before storing into a .txt file

my_trends = api.GetTrendsWoeid(my_woe_id)
trends = json.loads(my_trends)
but I get error : raise
TypeError(f'the JSON object must be str, bytes or bytearray, '
TypeError: the JSON object must be str, bytes or bytearray, not list
. I am using python 3.7. and python-twitter. What I am doing wrong?
Debugging such errors is part of the fun - how to do it?
First step: use python to inspect the thing that makes problems:
print(type(my_trends)) # will tell you it is a list
print(*my_trends) # prints all list elements wich tells you what they are
then look into the API for what you are using: twitter.api.Api.GetTrendsWoeid which would tell you, that:
which fully explains why you get
TypeError: the JSON object must be str, bytes or bytearray, not list.

json.loads() fails on my data read from a socket

i got some problems with my code. After i read a JSON received via socket by a Qt client in a python server, i want to get all the fields of that JSON so i can use it, but i got an error like this: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0). This is the code that cause the exception to raise.
data = connection.recv(1024)
temp = data.decode("utf-8")
jdata = json.loads(temp)
The exception is raised by json.loads(temp). I tried to be sure to have the right type for the loads function, i tried to copy the same string that i get from the socket into another str type and the function works well. Does anyone knows if there is something i overlooked?
update: I just found out that the JSON i get from the socket have a size that differs from a string with the same characters
the exception "json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)" usually indicates that the data you're trying to load is not valid JSON.
See Python JSON Docs
"If the data being deserialized is not a valid JSON document, a JSONDecodeError will be raised." (Scroll down to json.loads function)
Can you print out your temp variable? You'll be able to see the value you're trying to JSONDecode.

Parse value as int in HLC files

I am writing the template for a parametrized HashiCorp Nomad job. One of its parameters is priority, which is supposed to be an integer between 0 and 100.
Like other tools, Nomad supports variable interpolation, so that a variable can be defined at some point and later referenced. Nomad also allows to define "meta" variables, which are passed at runtime and can be used within the HLC file.
What I'm trying to do looks as follows:
job "my-job" {
parametrized {
meta_required = ["TASK_PRIORITY"]
}
priority = "${NOMAD_META_TASK_PRIORITY}"
...
}
The only way I have found to read those variables are within strings. Since the priority stanza expects an integer, the following error is thrown:
error parsing 'job': 1 error(s) decoding: * cannot parse 'Priority' as int: strconv.ParseInt: parsing "${NOMAD_META_TASK_PRIORITY}": invalid syntax
Is there any way to "cast" the string to an integer? Or, alternatively, is there any other way of referencing the variable that would work?
I ended up raising an issue on Github. Their response is that it's not yet possible to interpolate the priority field. See issue.

trying to extract phone number from a resume

When I try to use the findall function I get this error:
AttributeError: 'str' object has no attribute 'findall'
here is my code :
def phone(content):
content.findall(r"<.*><phone><.*><.*><.*>")
Are you trying to use a regular expression? In this case, the syntax is re.findall(pattern, string, flags=0), thus re.findall("<.*><phone><.*><.*><.*>", content) in your case. See the docs here. Note that this returns a list, and you can access results by indexing with [x].

Problems importing JSON data with R

I'm using the jsonlite library to try to get some JSON data and turn it into a data frame that I could use, but so far it hasn't worked. I've tried three methods so far:
testData = fromJSON("<json file location>")
Which outputs:
Error in feed_push_parser(readBin(con, raw(), n), reset = TRUE) :
parse error: trailing garbage
n_reply_to_status_id":null} {"contributors":null,"text":"Te
(right here) ------^
So I figured that if the quotes caused error, I'd just have to remove them:
singleString <- paste(readLines("<json file location>"), collapse=" ")
singleString = gsub('"', "",singleString)
singleString = fromJSON(singleString)
Which outputs:
Error: lexical error: invalid char in json text.
{contributors:null,text:A colour
(right here) ------^
It seems to be pointing to an 'o' in the text. If I delete that 'o' it just points to the 'n' that comes after it.
My last attempt I read on a forum post of someone having a similar problem that it should solve it:
stream = stream_in(file("<json file location>"))
I was pretty happy to see that this did not return an error and that a data frame named "stream" had been added to memory, but when I tried to view that data frame...
> View(stream)
Error in View : 'names' attribute [1] must be the same length as the vector [0]
I'm not exactly sure what this means or what I could do about it in this situation.
If you have an idea of I could get this data loaded correctly, I would deeply appreciate it. Thanks!
EDIT: Here is the JSON data in question: https://gist.github.com/geocachecs/f68d769aeed8e019a26cc230559bbf7f