The number of U.S. law enforcement officers shot dead on the job is up 78 percent this year compared with the same period last year, according to preliminary data from the National Law Enforcement Officers Memorial Fund.

In the wake of targeted attacks on police officers this summer in Dallas and in Baton Rouge, Louisiana, the analysis of law enforcement deaths across the country shows that the 32 firearms-related deaths recorded as of July 20 account for nearly half of the 67 line-of-duty deaths reported by police agencies, with ambushes comprising 14 of the fatal shootings.

The fatalities are still well below the rates of officer deaths in the 1970s, when the number of firearms-related fatalities peaked in 1973 with 156 officers. But Craig W. Floyd, president of the nonprofit officers memorial fund, called the rapid uptick this year “extremely troubling.”

“In the 1970s, you had a lot of parallels to what we are facing now. There was a lot of anti-authority sentiment and a lot of anti-police sentiment,” said Mr. Floyd, whose group maintains the national monument to fallen officers in Washington and keeps statistics on officer deaths. “They did become targets, just as they are becoming targets again today.”

Over the past decade, the number of officers fatally shot has averaged 52 a year. Firearms-related deaths reached their lowest point since the 1880s in 2013, when 33 officers were fatally shot, according to data from the officers memorial fund.

Advancements in police training and equipment, coupled with a lower crime rate in general, have helped bring down the number of line-of-duty deaths over the past several decades, Mr. Floyd said.

Yet the fund’s midyear report is being released Wednesday, just weeks after targeted shootings in Dallas and Baton Rouge took the lives of a total of eight police officers and prompted law enforcement agencies to roll out numerous safety precautions to protect their officers from similar attacks.

Departments across the country have ordered officers to patrol in pairs indefinitely. The New York Police Department announced this week that it had spent $7.5 million to purchase military-style protective equipment for its patrol officers.

“There’s not a police department in America that is spending as much money, as much thought and interest on this issue of officer safety,” said New York Police Commissioner William Bratton.

Gear to be distributed to officers this year includes 20,000 ballistic helmets and 6,000 heavy-duty bulletproof vests that would be capable of protecting an officer from the type of firearm used by the man who opened fire on officers in Baton Rouge, Commissioner Bratton said.

As departments strive to improve officer safety, a particular concern to Mr. Floyd is the number of ambush attacks.

According to previously reported data from the National Law Enforcement Officers Memorial Fund, the number of ambush-style killings has ranged from five in 2011 to 15 in 2014, with six such killings reported last year. Already this year, 14 ambush-style shootings have been reported.

“That is a frightening number of officers who have been assassinated because of the uniform they wear and the job that they do,” he said.

Seven officers were killed while stopping suspicious people, five were shot dead while executing tactical arrests or high-risk warrants, four were gunned down while attempting to arrest suspects and two were slain while handling prisoners.

Traffic-related fatalities accounted for 24 deaths so far this year. In three of the past four years, traffic-related fatalities have accounted for more deaths than firearms-related incidents, according to the officers memorial fund.

Jim Pasco, executive director of the National Fraternal Order of Police, said that while every officer death is a tragedy, data must be considered in a larger context.

Year-to-year fluctuations in police deaths aren’t necessarily indicative of the level of danger a beat cop would face on the street each day, Mr. Pasco said.

He counts the negative perception with which the public views police officers as their biggest problem.

“We should look to the substance rather than the shadows of the problem,” Mr. Pasco said. “We’ve got to adjust the perception of what kind of people police officers are.”

The recent high-profile deaths of civilians at the hands of police officers, coupled with fatal attacks on police, also have prompted political leaders to redouble efforts to repair soured relationships between police departments and communities of color.

President Obama this month hosted a marathon meeting with Black Lives Matter activists, civil rights leaders, police and elected officials in an effort to brainstorm solutions.

Participants were unable to reach much consensus. The president reported afterward that “there are still deep divisions about how to solve these problems” of race, policing and accusations of excessive force.

The president also met last week with Attorney General Loretta E. Lynch and FBI Director James B. Comey to discuss ways to protect law enforcement officers.

Among the proposals debated were providing more police departments with bulletproof vests and funding more training programs for dealing with active shooters and “de-escalating” confrontations with civilians.